Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6133395iog; Thu, 23 Jun 2022 12:03:18 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u/o0Orb222qKA5+UQgLvlhlUSZ4CXoiBUd/pMgSmPdxn2r98G9KxBM1140sNo+Kxd/IFPd X-Received: by 2002:a62:1687:0:b0:50d:3364:46d4 with SMTP id 129-20020a621687000000b0050d336446d4mr42243219pfw.74.1656010998088; Thu, 23 Jun 2022 12:03:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656010998; cv=none; d=google.com; s=arc-20160816; b=wJVMiCXZDUNe+4ZZDDQQpCAPN94VmtLMHZBDr43vYJDeKfwBiqDV/ZcS+gBbMLmTwJ eoj11Q/SI+n3x2Y428bJRxtXDF3ZbbbaXAe2q9VzLtrnyV0a8MVnVfC480IwmvtKbDSO zJBU1bgh4ml8OUKEfY1TM059WqsnZC2jObETy8oQuiqY8Q2wjpYA8gaAg/Pk8QFap7Ad shfofYfncaeVsTMBNbs2FXdOm4ETfedR4a+JKO9bhUlDLtW38KVannBD8rYkejbrIjmr 50kzU7FRdUgEyGpRvJmNKHyaGi7xeuw9Enn9pBHlR5YyYQJsVwD5ewczLnwHoeNqo0lD JnGA== 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=JkpWM9BqluFxiz5ch/RX+sr41C+yRYVq6Fum7NMVqU0=; b=CfCsnWn6N4BQEo/Pkj2NXVNxX+f87G3btifW3DXAKtLwULA1PVfAMFrvbk36hTYj0D IGd7MGMtFBE2b7BqLiIxaPJ8e/cvK4NWv9GSwrFxW0r67J6Hl8eiguQR90O6KfOTJt3z /aOsfsDqPraKknJT/omecdfqcK8Ow8V5tLD1/Uv3ce0wM92rzem9EM4OskDjz7ZcBiQR 7yIFaOp5xl9Arvkk9sBXY+IOSX+0FAD/Ue4Z6eip6FcUifJydOScVdOz6YCyVOFpU/hg 7/vaYzO/8FFbyfth7tE69tbmfQKNIS3n7xx1gi9UVoaLuQHN8i81PxZmEFwl1gXqG0jA dLLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=s3uMdcFI; 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 j11-20020a17090a2a8b00b001e312672c02si262281pjd.30.2022.06.23.12.03.06; Thu, 23 Jun 2022 12:03:18 -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=s3uMdcFI; 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 S236529AbiFWSNo (ORCPT + 99 others); Thu, 23 Jun 2022 14:13:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236556AbiFWSM1 (ORCPT ); Thu, 23 Jun 2022 14:12:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 712F99BB44; Thu, 23 Jun 2022 10:20:47 -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 C319F6159A; Thu, 23 Jun 2022 17:20:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ADEECC3411B; Thu, 23 Jun 2022 17:20:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656004846; bh=OpoznZMK1Ok1ZJg+f5Ff1jh+Gv+HjqOFJILFgEo6XZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s3uMdcFIu2x4wrhEJN3i+s2ps6ufdNKIi/qcQ1vcU8/dGqipCnkqsQHbIVnCWIjG3 m0pV5dlTIx/6a3jxFSMkfHLlxvUPfPERcQNUeWlhY6xFSSdUJw8q9EwEzoqGqLO9Ud 6wIvdZLXrVPLinXfRoC2GtGXM09vRY2TjH7Gxdkk= 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.19 129/234] random: check for signal_pending() outside of need_resched() check Date: Thu, 23 Jun 2022 18:43:16 +0200 Message-Id: <20220623164346.709939859@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164343.042598055@linuxfoundation.org> References: <20220623164343.042598055@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 @@ -549,13 +549,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);