Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6049429iog; Thu, 23 Jun 2022 10:15:32 -0700 (PDT) X-Google-Smtp-Source: AGRyM1selL4ngZ/Yj5rigWIOsNv4ePCqaIfW8aLlSrkZpvHU+Ugj+EVf3MkbSEd32dxinfYFdk0C X-Received: by 2002:a17:906:5d0d:b0:711:d149:7f2c with SMTP id g13-20020a1709065d0d00b00711d1497f2cmr9191095ejt.678.1656004531900; Thu, 23 Jun 2022 10:15:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656004531; cv=none; d=google.com; s=arc-20160816; b=E5z9vBKHCUQvDyEi9f/RUJM9Cn8jEzI10srnhgLyepIazJGCgWdFLR3wCzyG+8RMEh 58OXHiOPBegKgGosPcN2mc00GGU0JT5YXSeiK14LRk7fgclGL9Lvj355w95vzcBQ5Uzm JIMqLXrKkUTkifhGOGLViSk7eM1WWzbxK6YaFsBsYAsNVMkz1z8jwjWpfDgYW7DKHgjF kZfqCN14+HmBCYWVPYMAF7S0slh8gzqnP6T2ah4Ab1PVI4mtJuUmL1BsbsMsRTAQ+z53 0ZlrPSWXC9j1oUpVFUc7jousLDpyCQxEl1YJ9ohhhAudU2DpeeRGs6ZHpFaFtQzoV4Z3 IwKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=CZ3cA94GUtmXYihEfEEFXHtsvEGr+AjtoDZOuTCJ2ws=; b=YRnP8typzlM+hupyzO3f+/MW8JzZb4pxKy9QPD2VRf+QvhFlaCTbOY797jfri93sya YSDeUvOLi/Owu0NB9m9cPxQtp9a6J1LWGYinlSxjvORInQyhJwi3mJLrq2iJ3SAxif+H 6WjePS8KAemXueVYYekrKN/UDRugkHDKW329nq+1kecXJNRTIg1n3X+TvwH1VV4hCjj6 7wC22vtcaT2sCrwLsWzMXgQsE0T7FTTIqfIQh9tsPoFWSslDLq7FiB8wjTV03ilaoP2i neWMFhVHnHtCKisRwEjhHTs0psknToeAdUaXSGTRO0iH/DEj4CyjNFYhbYaHbvfQQRaP bKHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hRKhQnqO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z18-20020a17090674d200b00722eb684a60si6610116ejl.979.2022.06.23.10.15.06; Thu, 23 Jun 2022 10:15:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hRKhQnqO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230006AbiFWRGL (ORCPT + 99 others); Thu, 23 Jun 2022 13:06:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231519AbiFWREI (ORCPT ); Thu, 23 Jun 2022 13:04:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFA2A517C5; Thu, 23 Jun 2022 09:55:27 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CC16460B21; Thu, 23 Jun 2022 16:55:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A13DDC3411B; Thu, 23 Jun 2022 16:55:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656003318; bh=1M9PSXJVnGE6mA3Iv9p2eOcKv5jmu9LVJ0s2Uepl+pg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hRKhQnqOHaTwNFui6JitdFi5A3FRkwfwMv69gm+fwuz8HxDn4esh/mSmWkS+utnxt 4RzKjYNhdOUCmfiWZ12Jtko/Mi/L0uP8x72wfUChyq4UKUzguNIlIoEBWhxF4yHJMX Zz9sMCfMJ1fxuZXASCTPR7MlpsE0zBQF5n9xFbLo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jann Horn , "Jason A. Donenfeld" Subject: [PATCH 4.9 172/264] random: check for signal_pending() outside of need_resched() check Date: Thu, 23 Jun 2022 18:42:45 +0200 Message-Id: <20220623164348.932310056@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164344.053938039@linuxfoundation.org> References: <20220623164344.053938039@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jann Horn commit 1448769c9cdb69ad65287f4f7ab58bc5f2f5d7ba upstream. signal_pending() checks TIF_NOTIFY_SIGNAL and TIF_SIGPENDING, which signal that the task should bail out of the syscall when possible. This is a separate concept from need_resched(), which checks TIF_NEED_RESCHED, signaling that the task should preempt. In particular, with the current code, the signal_pending() bailout probably won't work reliably. Change this to look like other functions that read lots of data, such as read_zero(). Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Jann Horn Signed-off-by: Jason A. Donenfeld Signed-off-by: Greg Kroah-Hartman --- drivers/char/random.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -550,13 +550,13 @@ static ssize_t get_random_bytes_user(voi } do { - if (large_request && need_resched()) { + if (large_request) { if (signal_pending(current)) { if (!ret) ret = -ERESTARTSYS; break; } - schedule(); + cond_resched(); } chacha20_block(chacha_state, output);