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 Netto X-Patchwork-Id: 1932131 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=OlgyX3fY; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VY8nb11DGz1ydW for ; Tue, 7 May 2024 04:19:31 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A0D863858C3A for ; Mon, 6 May 2024 18:19:28 +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-Google-Smtp-Source: AGHT+IFNRhhtmiUuSjNrbTFr9PvgR669hhztMyug/s9h1BRAYf9XZHZmX7NYUndII3T7xXl2lqMYrg== 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+incoming=patchwork.ozlabs.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 (); }