From patchwork Mon May 6 18:19:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 795029 Delivered-To: patch@linaro.org Received: by 2002:adf:a453:0:b0:34e:ceec:bfcd with SMTP id e19csp1055991wra; Mon, 6 May 2024 11:19:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXjPvdKY/GF8Z3TP61VJYUg3umC8viclyGhOHq+az8zttg9LWlvQGw33DWJFslxmEPPepQXW26UWzkePKQ1d61W X-Google-Smtp-Source: AGHT+IEoOX3vIZtjy3Jpq0bQ7Rynh1p6tZ3SjLQFoZtBRfpaUoFCFk5RCnaMEhQcGE0BrUu/JSG2 X-Received: by 2002:a05:6214:d45:b0:6a0:aac9:c56f with SMTP id 5-20020a0562140d4500b006a0aac9c56fmr16082015qvr.33.1715019564412; Mon, 06 May 2024 11:19:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715019564; cv=pass; d=google.com; s=arc-20160816; b=hEcikUTdjCn29u1wqEI/ix7fSJC5QjUleCJenCpB2IxN0SCJbhXZHkZhG8N0zFZpnV pRiUSSPojLOVuVsKVIHJQ1+UTL4OSBQlnLq98Th2i4YHQSktkvnRSxAqTje4L3mws00a cByCUzsr7jVBaLzitKmmQGekaMaHLYaS+uUOhpubhhNEO7ppTj/C8d9hmQq9SiuY70NR 27E4jJRUU5tzuxDr0bqsJ21Ehuyx4vFuonGhSaamDWKSxHUBIxnWoM1/zEawAm8Ev9ux DEPRXMF9WrrIfOzcMZYvV0ks3QeNfXsdzFryIRK6JBtvO1mX/9Ntca9N/LpMAuQt7RHv NWeg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=f0YjzEstFQ1W5nNmePbwGMLegGA7zQXTUOW8eIOQ0yw=; fh=dHLBnA+MhGtNtN2B2JMAELi4oD+gmgMg7DL8H0jYbkI=; b=YMN7YwzOZup1ZH+SUpE080gMvuJn2uvxT4jXrZcxtI4YtKOiRSr5sGy4qrOOEU0oxa 0vJHoHcWlJpHnLUN9Xc+f1yDgWH//Y40Sd+sUI2ZV4pCbFlyjBOoDOPHSjoh4/PL+IUX xY/wZ1365BZnEFcAZWrPngmwNqDS1CYLjd6x8knYcHPVpm2e0LPY33qOT4bYZNDbHRaS K40rsl67j+uz5aD7RuGTFk/2I3bRBIGo1R5pOooUObzPWrhUec3YQBgeyNLeiMBOVUeq 9XhRpBgcawrojwDlLQ/jxrux1Jxl76pmUrbTlxDCsp1HidWRozeQ3Va5TVMfwdm59dpk cz8w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OlgyX3fY; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id q10-20020a056214194a00b006a081d971b7si9883950qvk.260.2024.05.06.11.19.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 11:19:24 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OlgyX3fY; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 09AEC3858CD1 for ; Mon, 6 May 2024 18:19:24 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by sourceware.org (Postfix) with ESMTPS id 7DD6D3858D1E for ; Mon, 6 May 2024 18:19:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7DD6D3858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7DD6D3858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::532 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715019554; cv=none; b=u9YRKJr/8+XfXT9pwtxzqzQ9lIz+6Zj1eWpM4EKAosWH0qWTXtSqh/5kb7GgkpKQw+1A3OO2LbwNw/kp61Yg3D0B779nK12uM/5adfFkh7wF1fN5vZmTt27NLIqEyHx+fhYDF6bzt8VYBmzzLgItdVyGMGXBMLdzuJYiRjWsr0Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715019554; c=relaxed/simple; bh=5nAKwlspFuLDCAQYu1thc2VSg/v8wfSNQ+xlY+DMvK0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=OYHaBDGCvMislmf2CJ5x6IySdtrBKbi2qqqO9Lo6GNEkQE49f+tfJHlN9J/SUDcBthIr7lsCxxqIWGKXgnRrj1KFIJRx8sE8mWmz6pHOqfJpDlAI6zhKP6JZK7oY2iO+SVBnHiLO2PgFmsusJlFTohDPtw14iaeYsFldcd095uE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-5ce2aada130so1626227a12.1 for ; Mon, 06 May 2024 11:19:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715019551; x=1715624351; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=f0YjzEstFQ1W5nNmePbwGMLegGA7zQXTUOW8eIOQ0yw=; b=OlgyX3fYYyRQarzc/AOJx+FvvwJMTdUfajjOCo4Tyr0DFkKZhwDnepjkjA3malpbJc w/6VZNCPfDr4Lg2DkaqF25fDFoZfFTRb9uMiF8b1OjoMvPpteH6Sfkws9AKPD8ARu0Fe VEIV8EoKN6z8LIJTdhL43iteIxgPzMDB+PbqNMjtnDfYjqr+FF+rH1EuoQTI8O1I2zEm JKFh8rEjjl66U+0YhWVTnqDc69Fy7TwCwSn2wdtK7/Pn95X1YpwZKvgp7HZHgcIXPcwh 358WO5MVhs8fj7oQE0wBH5cxHB7e4wd5sQPym1EbrnlNLrsLankh3xTggeq+lCsM8enU 3bHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715019551; x=1715624351; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=f0YjzEstFQ1W5nNmePbwGMLegGA7zQXTUOW8eIOQ0yw=; b=hTlr1gwRqhePXxtrmbQoJYO2vHNLietjq162dfIDIEOiUiKTuLpa6gYEhIXHBfZvcj tXChMy7NcMX3cM/xDp6eRGx4LAxcGQQNEUsMx9CSEO/L4Lp7gowjpsKGdOTCK6Urx8dF xbdfBqaZSFYNI5cYypChaJOhfDxcW6vrhbRhmEsG5HmsC96vz51qrLaDytFQm0Iv3KHR +ayhGeJxXOl5Jf6dF8Agd6eIhI/2fTBOjRFPCpGrlmT2YgFJf4wso+cSROGWBou/Vki9 5shLdFvUQy/tOS1jXP1bvE8Recas0b45ddXE9kfoY0jVOmNhEhT2pWzauSlTaC/CjSC9 /WBQ== X-Gm-Message-State: AOJu0Yw4P1wxCtWh82bon1U8a4ckvp6aDIAQ3y0//VAQcoWvUXUYWuWq HtrW/C5/YhG4mLR6D399uNnCybN5ZFWY8X/+tyHaewtuplAwOZNGnatj7yxMeQuJ5bSox41sfCt Z X-Received: by 2002:a17:90a:6341:b0:2b2:a5aa:917b with SMTP id v1-20020a17090a634100b002b2a5aa917bmr9210707pjs.3.1715019550657; Mon, 06 May 2024 11:19:10 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:6e56:fc45:bb45:8b35:9b81]) by smtp.gmail.com with ESMTPSA id sy15-20020a17090b2d0f00b002a5d20778ebsm10376120pjb.32.2024.05.06.11.19.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 11:19:09 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH] stdlib: fix arc4random fallback to /dev/urandom (BZ 31612) Date: Mon, 6 May 2024 15:19:02 -0300 Message-ID: <20240506181906.1798367-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patch=linaro.org@sourceware.org The __getrandom_nocancel used by __arc4random_buf uses INLINE_SYSCALL_CALL (which returns -1/errno) and the loop checks for the return value instead of errno to fallback to /dev/urandom. The malloc code now uses __getrandom_nocancel_nostatus, which uses INTERNAL_SYSCALL_CALL, so there is no need to use the variant that does not set errno (BZ#29624). Checked on x86_64-linux-gnu. Reviewed-by: Xi Ruoyao # as the fool who introduced the bug --- stdlib/arc4random.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/arc4random.c b/stdlib/arc4random.c index 3ae8fc1302..7818cb9cf6 100644 --- a/stdlib/arc4random.c +++ b/stdlib/arc4random.c @@ -51,7 +51,7 @@ __arc4random_buf (void *p, size_t n) n -= l; continue; /* Interrupted by a signal; keep going. */ } - else if (l == -ENOSYS) + else if (l < 0 && errno == ENOSYS) break; /* No syscall, so fallback to /dev/urandom. */ arc4random_getrandom_failure (); }