From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795951433; b=heiiUgfQBotW+TRO3TrOh/HtpYgxlWEIvRzrSHgJQzrD9LMUpdaDEjADYCLbOPKCpNTw gC0d9obgqzJQMRspDgfMf2aMxI5ID7ThQwbhq0tngNhzebBbqt35REFHL+NRA8+wxgDgX PT1IY/amTCA88XK9uvzueccUrZoN2kqUg6KwJYkJ0fauiICzEIG2slTJSRMmJ55Irtfyq UX9xCxdyRlX5wM+qa4ZWrkFvJqiyrvAwXMiwrtj9Bs1SQ0fLZ5mGJI1b2GB5Dut1TS5a/ rAZEgaMXdfBUGLk5nqb2YLk6rqGrxIyy2N4j/B4cS04T8z5vMTfI+kdG+yGYu73NQEQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795951433; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=qydpio4mwaTIWK/FSC1Ry9fJ+0LccuNJsPtQxUfdPyA=; b=gwRRMEp6ma9fy84xN7ezmU4sCIScB6ZfvIdQyvt+QndGwWoPbSdNDgXM9o1mCOLCSUoM HTfdFkFFADTQFV2rvTltHhAYNfcEwUfJjcy2Z3RCvYrN6YSPj+Q8ya/HSSc0qkW8pstTu /a732KghPiISGUD6Fs/JlMY6AvKwUwtnD8rwD92NTkPfSCdur4/vr3CYc4er8Z+n+vTFh j7wt3Z92GA+xdFsM1YyalCqEgSB8pxIQUYZEWzZo47gs1Bf3dFt0Yx08G9+q/K0OTIrJs 0WOnjOx1qwcGWLLRnGgiLBswV13OaerLbwUDHzgS9QGgc9B99Wzhy2TbcW/AnK7Jqtg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GWTW37LW; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DEE55606A323 for ; Sun, 29 Nov 2026 11:23:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GWTW37LW Received: by smtp.kernel.org (Postfix) with ESMTPSA id A5FF91F000C1; Sun, 29 Nov 2026 11:23:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795951433; bh=qydpio4mwaTIWK/FSC1Ry9fJ+0LccuNJsPtQxUfdPyA=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=GWTW37LWtbdcIWvqMXE6Or69QmNew61m1VivB2qQYbxeS6Ql36XWFaNXxYVztUFcq awJxk0awbpa3zER18aqGYgh0pGN2rQPWKGpKmAfF4mUHQhz7r+EWnohdlEBbG+CKGQ eWleKGVInjl4qp6Kj6NVWLjf6pT2qpY1psMThltinaXRXLT6hgCvM/1ofv1/KlNiTj jhk82VQykRa/ayIRvOMhw6i4FOCgl5MJOjGwIUe6DdR9r8oOxVvSqrOzjs9zgGvUjQ QhSXz+ZrSohE99c8Y6xVesZwrpOj3OylICzmR7CgQy6wZbkuHoxhTDDSG8JToyhrlp eSibV7e6mtNSg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v6 2/3] riscv: probes: reject probes inside an LR/SC sequence Reply-To: sashiko-reviews@lists.linux.dev To: "Vladimir Kondratiev" Cc: linux-trace-kernel@vger.kernel.org In-Reply-To: <20261129-probes-in-lrsc-v6-2-f97e90cf07cf@mobileye.com> References: <20261129-probes-in-lrsc-v6-0-f97e90cf07cf@mobileye.com> <20261129-probes-in-lrsc-v6-2-f97e90cf07cf@mobileye.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 29 Nov 2026 11:23:53 +0000 X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] riscv: probes: uprobe_in_lrsc_body() accepts probe when first page read fails -- commit f31772122cc1adbb7329eb88b2f9554c8eb7d103 Author: Vladimir Kondratiev riscv: probes: reject probes inside an LR/SC sequence This commit adds forward control-flow analysis to reject kprobes and uprobes placed inside a constrained LR/SC atomic sequence. > diff --git a/arch/riscv/kernel/probes/uprobes.c b/arch/riscv/kernel/probe= s/uprobes.c > index eb177d0ce8ab0..d97a102621665 100644 > --- a/arch/riscv/kernel/probes/uprobes.c > +++ b/arch/riscv/kernel/probes/uprobes.c > @@ -28,6 +28,34 @@ unsigned long uprobe_get_swbp_addr(struct pt_regs *reg= s) > return instruction_pointer(regs); > } > =20 > +/* > + * Is the instruction at addr inside a constrained LR/SC sequence? Only = the > + * probed instruction was copied, so read the text that follows it from = the > + * task. The caller holds mmap_lock, as uprobe_write_opcode() requires t= oo. > + * Text that cannot be read ends the scan early, which accepts the probe. > + */ > +static bool uprobe_in_lrsc_body(struct mm_struct *mm, unsigned long addr) > +{ > + u16 buf[RISCV_LRSC_SCAN_BYTES / sizeof(u16)]; > + struct vm_area_struct *vma; > + struct page *page; > + size_t got =3D 0; > + int len; > + > + while (got < sizeof(buf)) { > + len =3D min_t(size_t, sizeof(buf) - got, > + PAGE_SIZE - offset_in_page(addr + got)); > + page =3D get_user_page_vma_remote(mm, addr + got, FOLL_FORCE, &vma); > + if (IS_ERR(page)) > + break; > + uprobe_copy_from_page(page, addr + got, (void *)buf + got, len); > + put_page(page); > + got +=3D len; > + } > + > + return riscv_probe_in_lrsc_body(buf, got); > +} > + > int arch_uprobe_analyze_insn(struct arch_uprobe *auprobe, struct mm_stru= ct *mm, > unsigned long addr) > { > @@ -53,6 +81,9 @@ int arch_uprobe_analyze_insn(struct arch_uprobe *auprob= e, struct mm_struct *mm, > return -EINVAL; > } > =20 > + if (uprobe_in_lrsc_body(mm, addr)) > + return -EINVAL; > + > return 0; > } [Severity: Medium] Can uprobe_in_lrsc_body() accept a probe inside an LR/SC sequence when get_user_page_vma_remote() fails on the first page? If the first page fault fails (for example with -EINTR when a fatal signal is pending during uprobe_mmap(), or -ENOMEM), the loop breaks with got =3D= =3D 0 and riscv_probe_in_lrsc_body(buf, 0) returns false without inspecting even the instruction already copied into auprobe->insn. arch_uprobe_analyze_insn() then returns 0, causing prepare_uprobe() to set UPROBE_COPY_INSN on uprobe->flags permanently. Later installs of the same uprobe in other tasks or VMAs see UPROBE_COPY_INSN set, skip prepare_uprobe(), and plant the breakpoint inside the LR/SC sequence or on an SC instruction, livelocking the traced process. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261129-probes-in-= lrsc-v6-0-f97e90cf07cf@mobileye.com?part=3D2