Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp169964lqo; Tue, 7 May 2024 16:28:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUAnbid9ppkRi3eE6qcGvLe0az6DFIxwLmw++xUl4cILZdwYEyCvxwsISKOlAohW2Uw0rrFDIo2DUlhYR0GKf8jtnHD2nUg4YbBJGqMyw== X-Google-Smtp-Source: AGHT+IFrzWh/Bk7Uv4Q1ZZ2nbCYhazEuvk7NaCieAKJBlRNyUp/n8bZs3Vfa1pWOFfc4Dm9DMyCP X-Received: by 2002:a2e:9987:0:b0:2de:48ef:c3e1 with SMTP id 38308e7fff4ca-2e446f816edmr5987951fa.21.1715124522194; Tue, 07 May 2024 16:28:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715124522; cv=pass; d=google.com; s=arc-20160816; b=0MpUoozaniNRPdkdxvpFEsgF7G+DNSTWQ/im1KQnVEk2b2KqtHhQcKPKkjfudoTNNU bep6GVCfAupsqBrPS6WuheF5eZCrFnywAupGg1koT5EXVFvCES6EznzumF27GtA43izX Dk8d3iJ5eTp06ovrdn9SLgmbqlo4E5OMMZRfKoRH9lB7HmGbdMZEWn+PnG2NlRCmlJC3 L0UhOeiydsyJrwwBrNAHfXIycT1Zwy4P9hFD+S09vvAeLOmORucVk23uhKoiB+krW7S3 lV5L46bCvI1bO+hVY7XrQ3CKVQDIWE+w4b18ml5DRtzyY81CKQnzWx7ol4ovvTgCBGeL A5sg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=lc6osfD/JSbFnDsBeQOIoBHl3WYTj8bBo92bNtHSVGs=; fh=EDJqqaS8a68ZkCKuzDeaPj3qTYJtMV2dFpqZWHmcO5c=; b=IWmLcp4TKdqANh/UmeKQZ7OElQI595q29dAqZzwKAgLcn6vNjYZDNG31eKtKmnTQTG kgg9hbIlroItkl+awFtNR4Urq0JosIcxD3WblHzy8bgiM+llGH7IwhksEHKwY8m6Oc7A sM2xTUWd/Xr0OeYOJnMMPDhiNiNfEh0FIfPy8JLV4MXxemGXcLVZNmDPA3LEecoYx1Wo gG1Ys0WPWdyL45/gCNha7MxjtdrigckR4oAL92P3xGKOvxPAEUVUHrrh6X0XPGmCxi7v hohUGguhmw9knNCnCigw6VTnReQidUVi+TNnqrNanwuCBC9f0egIj1OTnRBAn0WeXSck ENQg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FRP7M2Ws; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-172369-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172369-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id r26-20020aa7da1a000000b00572a0808798si6244344eds.640.2024.05.07.16.28.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 16:28:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-172369-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FRP7M2Ws; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-172369-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172369-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id B73B11F221F2 for ; Tue, 7 May 2024 23:28:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C25CD13F433; Tue, 7 May 2024 23:08:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FRP7M2Ws" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB10913F426; Tue, 7 May 2024 23:08:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715123334; cv=none; b=S2lK31FkfcyfXsYhxNIHEfWCZE+LJS1/bkIry2gvLggWydnyPP6j/EU+A0FVjT2MmyZfV5083/v8I4YXCcLPTsFXGzXDEofIIz43Gil3qDH7CyMcpGDzT3EAhTwCBv81laG3HK+YdDlF/G2vIAijw0S9wIbCBIm9pWIUpVzZXAw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715123334; c=relaxed/simple; bh=zjAZlI1pbZ1tfO45FvuApgI5jyD/USyAPo18X3Wlq1o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AcgQ+otYjmqR0dTCq12d48s4zkVYSSWNkz5uFTSLgfCfvUD609uZ5xlXFw0Yn7fRAmLzon6BcSVCAHK4g7K7sf0hUp9optqTaJXZvzhDK7zKlKgMFUdxAh1nwNjtzTLxqqZ9VUkBz+aRP9o9ihNbEX4VD2Fax8VxulGUais5fkY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FRP7M2Ws; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7DEC9C4AF17; Tue, 7 May 2024 23:08:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715123333; bh=zjAZlI1pbZ1tfO45FvuApgI5jyD/USyAPo18X3Wlq1o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FRP7M2WsPsbPKZeyFvORdG6I9geTzGZyicqPlSFwBrtEV7VTfogR/VzfBAho+0zGH 3rtxf4XGXquAl+fUWgnFPf4MoZ3KF1hCqFnkqp6P4BwmxhUTO7cjSRmby2spnjUkZm /VuT29C4YiV9aGyWMpUPp9c7ZHPx2B33Z0FEAm1gHhsALE3MI9uii9I8Q7yrh1w63O 2PCjQH3mEjgd1Ifw/snId6jF+veXRXTHlTuruG/hoZBOK3V2HZEtPNOiVcHgCsPDZ7 k4o9dCAdYoxRH2hAaZiwvCcU3r+w8lkdf7IE9b90v32vUuhRRVT2GJ3X+VsATBu+hE f7eF9Uh55rVFQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Zqiang , syzbot+dce04ed6d1438ad69656@syzkaller.appspotmail.com, Thomas Gleixner , Sasha Levin , peterz@infradead.org, tj@kernel.org, edumazet@google.com, bigeasy@linutronix.de, pabeni@redhat.com, CruzZhao@linux.alibaba.com Subject: [PATCH AUTOSEL 6.8 27/52] softirq: Fix suspicious RCU usage in __do_softirq() Date: Tue, 7 May 2024 19:06:53 -0400 Message-ID: <20240507230800.392128-27-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240507230800.392128-1-sashal@kernel.org> References: <20240507230800.392128-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.8.9 Content-Transfer-Encoding: 8bit From: Zqiang [ Upstream commit 1dd1eff161bd55968d3d46bc36def62d71fb4785 ] Currently, the condition "__this_cpu_read(ksoftirqd) == current" is used to invoke rcu_softirq_qs() in ksoftirqd tasks context for non-RT kernels. This works correctly as long as the context is actually task context but this condition is wrong when: - the current task is ksoftirqd - the task is interrupted in a RCU read side critical section - __do_softirq() is invoked on return from interrupt Syzkaller triggered the following scenario: -> finish_task_switch() -> put_task_struct_rcu_user() -> call_rcu(&task->rcu, delayed_put_task_struct) -> __kasan_record_aux_stack() -> pfn_valid() -> rcu_read_lock_sched() __irq_exit_rcu() -> __do_softirq)() -> if (!IS_ENABLED(CONFIG_PREEMPT_RT) && __this_cpu_read(ksoftirqd) == current) -> rcu_softirq_qs() -> RCU_LOCKDEP_WARN(lock_is_held(&rcu_sched_lock_map)) The rcu quiescent state is reported in the rcu-read critical section, so the lockdep warning is triggered. Fix this by splitting out the inner working of __do_softirq() into a helper function which takes an argument to distinguish between ksoftirqd task context and interrupted context and invoke it from the relevant call sites with the proper context information and use that for the conditional invocation of rcu_softirq_qs(). Reported-by: syzbot+dce04ed6d1438ad69656@syzkaller.appspotmail.com Suggested-by: Thomas Gleixner Signed-off-by: Zqiang Signed-off-by: Thomas Gleixner Link: https://lore.kernel.org/r/20240427102808.29356-1-qiang.zhang1211@gmail.com Link: https://lore.kernel.org/lkml/8f281a10-b85a-4586-9586-5bbc12dc784f@paulmck-laptop/T/#mea8aba4abfcb97bbf499d169ce7f30c4cff1b0e3 Signed-off-by: Sasha Levin --- kernel/softirq.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/kernel/softirq.c b/kernel/softirq.c index 210cf5f8d92c2..bd9716d7bb638 100644 --- a/kernel/softirq.c +++ b/kernel/softirq.c @@ -507,7 +507,7 @@ static inline bool lockdep_softirq_start(void) { return false; } static inline void lockdep_softirq_end(bool in_hardirq) { } #endif -asmlinkage __visible void __softirq_entry __do_softirq(void) +static void handle_softirqs(bool ksirqd) { unsigned long end = jiffies + MAX_SOFTIRQ_TIME; unsigned long old_flags = current->flags; @@ -562,8 +562,7 @@ asmlinkage __visible void __softirq_entry __do_softirq(void) pending >>= softirq_bit; } - if (!IS_ENABLED(CONFIG_PREEMPT_RT) && - __this_cpu_read(ksoftirqd) == current) + if (!IS_ENABLED(CONFIG_PREEMPT_RT) && ksirqd) rcu_softirq_qs(); local_irq_disable(); @@ -583,6 +582,11 @@ asmlinkage __visible void __softirq_entry __do_softirq(void) current_restore_flags(old_flags, PF_MEMALLOC); } +asmlinkage __visible void __softirq_entry __do_softirq(void) +{ + handle_softirqs(false); +} + /** * irq_enter_rcu - Enter an interrupt context with RCU watching */ @@ -918,7 +922,7 @@ static void run_ksoftirqd(unsigned int cpu) * We can safely run softirq on inline stack, as we are not deep * in the task stack here. */ - __do_softirq(); + handle_softirqs(true); ksoftirqd_run_end(); cond_resched(); return; -- 2.43.0