From mboxrd@z Thu Jan 1 00:00:00 1970 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 D82E024B28; Wed, 8 Apr 2026 18:31:43 +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=1775673103; cv=none; b=Hjz7jsCDlCa4T/+32+T2/fkXLxUPx4tJmp5Wm9kWLDJZfWbRB7XLuMZ1aPd2QQXKb4N1s3PQwoB3PiMBnHKA8bXHRPJZY/QTuR3htQYpj2/wZhD0no3a9UeF76DcVphi4ps+5jhrWq8UnrACxmHuoYN4mAXQTv7wAmRJOpW33rM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775673103; c=relaxed/simple; bh=RcYJw67zqP/2vgT/4zyMMcDS20WzAP1TQMy3lhY27Jk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DoIcGHE5sX/UdVev5Oozfpolx9yqVyTWoBlObnQZda7keiy/gYK1LsOZP047Yk6bdU1IQaF1OPj0FAs/yylkT26oxg7OUCrur4jv6FiOG9ATVDwLwnyip8Nyand1iRnbYn+FAU1+EPUxEfFhoi3ksPxPzj3vFeNVyRV5ZCu1dG0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=zxu4MfyG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="zxu4MfyG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E328C19421; Wed, 8 Apr 2026 18:31:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1775673103; bh=RcYJw67zqP/2vgT/4zyMMcDS20WzAP1TQMy3lhY27Jk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zxu4MfyG6wYCdNPaoGBn5qGwjrhJUsa9wqiO6bkLkhsH12TBeG+WXP3issGrfUaLo 3Ua8MqmrXeD+R66zIdy4A+KsiirZL3SXHzPvfyW5QATkZREl9ZPst+UpKMM1vxbOZv ifik9p+HuKxblQZnTfWL218M7f1wEhIMtmKI5p0A= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Varun R Mallya , Kumar Kartikeya Dwivedi , Leon Hwang , Jiri Olsa , Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.18 102/277] bpf: Reject sleepable kprobe_multi programs at attach time Date: Wed, 8 Apr 2026 20:01:27 +0200 Message-ID: <20260408175937.680594892@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260408175933.836769063@linuxfoundation.org> References: <20260408175933.836769063@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Varun R Mallya [ Upstream commit eb7024bfcc5f68ed11ed9dd4891a3073c15f04a8 ] kprobe.multi programs run in atomic/RCU context and cannot sleep. However, bpf_kprobe_multi_link_attach() did not validate whether the program being attached had the sleepable flag set, allowing sleepable helpers such as bpf_copy_from_user() to be invoked from a non-sleepable context. This causes a "sleeping function called from invalid context" splat: BUG: sleeping function called from invalid context at ./include/linux/uaccess.h:169 in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 1787, name: sudo preempt_count: 1, expected: 0 RCU nest depth: 2, expected: 0 Fix this by rejecting sleepable programs early in bpf_kprobe_multi_link_attach(), before any further processing. Fixes: 0dcac2725406 ("bpf: Add multi kprobe link") Signed-off-by: Varun R Mallya Acked-by: Kumar Kartikeya Dwivedi Acked-by: Leon Hwang Acked-by: Jiri Olsa Link: https://lore.kernel.org/r/20260401191126.440683-1-varunrmallya@gmail.com Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- kernel/trace/bpf_trace.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index d8da00fe73f0b..70f1292b7ddbd 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -2739,6 +2739,10 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr if (!is_kprobe_multi(prog)) return -EINVAL; + /* kprobe_multi is not allowed to be sleepable. */ + if (prog->sleepable) + return -EINVAL; + /* Writing to context is not allowed for kprobes. */ if (prog->aux->kprobe_write_ctx) return -EINVAL; -- 2.53.0