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=1796361940; b=j9cWBGc58dW7HDotNtyxwdumtoT/KyzUIaDT6VuGgaJNiGxWAdQ9nmFI2ycd25AcU2Rf Uyg3xWHEYJ8+5FIFk2WyQ8TLLTuYe+tnLJuZer81L8SWnowoakGOx7PMzKg0vry0c66De Zs3ygdFTamAWLcvfpqn59gdvTmNoRby+06YBXCyGlCQYJEtHpC83u5c6psUys3Hf5aump X0UbS03cIx8/QVWxLcEEXNR2t0b2rgKed/WICo/VVdb16C2RKJvORdSXemKPGwX0GOP02 oxC6/saqf/HNJIJfQmABdHCSDOhisi+jDOdF5QLIGrTg41ljekzrg3oXq2ksU5fyBRw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796361940; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=zstI8eGJDjvmG10IsCSjks39npk8ohQckqwWunzepgA=; b=H94dypjr7Ge+S+DWgphGsv3yoNYVmmU9oknsLkEq46j+ZiC54kGJFrWlnUbvdOCGXAUh xjiMtqo2bLTNHQtivppUYNawaHr/t/2mbNva98I4raLfyqQy/aq87TeysH5Yf/5x9o4P3 qPH7DedRj+rgAA7lGk2kw1d3bhN6y5+24J6PD6yYRn8Q8bGMwGN8LuY326YmsLQw4lG+j SvqEQfYfE00Z2AXRKaupwRtrJ94ZyQhYEVDwgdmguUQWRoH1BSzy08V6tYSWgCVT5uMtd cxnMt1LcJEc/JcBNVhYL4XDyhjJzHK6VEsXYRZYK4CSxWdzKDs5OAwolsVTlyOsTgMg== 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=DU2pqfQL; 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 161A4606A322 for ; Fri, 4 Dec 2026 05:25:39 +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=DU2pqfQL Received: by smtp.kernel.org (Postfix) with ESMTPSA id 490621F000CE; Fri, 4 Dec 2026 05:25:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796361939; bh=zstI8eGJDjvmG10IsCSjks39npk8ohQckqwWunzepgA=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=DU2pqfQLVxG7NYW+aPWQyZ5nuQxt0c/KBPSTw017BQfumkLDCFxdjn5FburrtnR5R UN7j8Doby5oAZONAQltouq+v1QPQiBwNt2t3d10sKug9avuGT8Uzd57w2imkQAOkD9 k1yc0L83aOE1xS+thBeBl3C3DCBILnH06OUBxzEWqXWx6KqO0FY7pOANVc/BWSGjBy waRBmNDaQRdWcIYSyIpRa1MPI2rbC9AgAPWHOu/O6iSn13fl8YAuWg7GO6vG4XbZpl kptpiH56wR/OhlkJXG05vTST5BQLIbGloflqz2VuJd6x+YWUWIXY0XWvP6ZBEe+JUX Db14BGYc/3rMg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 3/3] livepatch: check task stacks against a sorted range table Reply-To: sashiko-reviews@lists.linux.dev To: =?utf-8?b?Wmh1LCBZaQ==?= , "Josh Poimboeuf" , "Miroslav Benes" , "Petr Mladek" , "Joe Lawrence" , "Song Liu" , "Wilson Felipe Pereira" , "Dylan Hatch" Cc: live-patching@vger.kernel.org In-Reply-To: <370addaa39777621da6828eea8e1d0b17bc26b2e.1796357900.git.chuyee@google.com> References: <370addaa39777621da6828eea8e1d0b17bc26b2e.1796357900.git.chuyee@google.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 05:25:38 +0000 X-Mailing-List: live-patching@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] livepatch: klp_discard_nops() frees old_name still referenced by range table -- commit 66c10fb7e04a8201e4389a5450561bd570f25d7a Author: Zhu, Yi livepatch: check task stacks against a sorted range table This commit builds an RCU-published sorted table of active transition function ranges so klp_check_stack() can check each stack entry with bsearch() instead of scanning every patched function per task. > diff --git a/kernel/livepatch/transition.c b/kernel/livepatch/transition.c > index 07e786c2d8123..6756d5ccdea89 100644 > --- a/kernel/livepatch/transition.c > +++ b/kernel/livepatch/transition.c [ ... ] > @@ -241,23 +272,118 @@ static int klp_check_stack_func(struct klp_func *f= unc, unsigned long *entries, [ ... ] > +void klp_update_stack_ranges(void) > +{ [ ... ] > + klp_for_each_object(klp_transition_patch, obj) { > + if (!obj->patched) > + continue; > + klp_for_each_func(obj, func) { > + unsigned long func_addr, func_size; > + > + klp_func_stack_range(func, &func_addr, &func_size); > + if (!func_size) > + continue; > + new->range[i].start =3D func_addr; > + new->range[i].end =3D func_addr + func_size; > + new->range[i].name =3D func->old_name; > + i++; > + } > + } [Severity: Medium] Can range->name become a dangling pointer to a freed func->old_name while a reader still uses an older klp_stack_ranges table? For a dynamic NOP in a replacing patch, func->old_name is freed synchronous= ly with kfree() in klp_free_func_nop(), whereas klp_stack_ranges is freed with kvfree_rcu(). In klp_complete_transition(), klp_discard_nops() runs before klp_synchronize_transition() and before clearing klp_stack_ranges. If a target module patched by a dynamic NOP unloads during a transition, klp_module_going() unpatches that object before replacing the table. A concurrent __klp_sched_try_switch() reader can still hold the old table T1 when a forced transition completes: CPU0 CPU1 klp_module_going() klp_cleanup_module_patches_limited() obj->patched =3D false __klp_sched_try_switch() klp_check_stack() ranges =3D klp_stack_ranges (T1) klp_update_stack_ranges() rcu_replace_pointer(..., T2) kvfree_rcu(T1, rcu) mutex_unlock(&klp_mutex) klp_force_transition() klp_complete_transition() klp_discard_nops() klp_free_func_nop() kfree(func->old_name) klp_try_switch_task() pr_debug(..., old_name) <-- use-after-free Because obj->patched is already false and klp_resched_disable() does not wa= it for preemption-disabled readers already in __klp_sched_try_switch(), klp_discard_nops() can free func->old_name with no RCU grace period. If CPU1's stack matches the stale range, pr_debug() reads freed memory. Clearing klp_stack_ranges and synchronizing before klp_discard_nops(), or freeing func->old_name via RCU, would keep the string alive for readers. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796357900.gi= t.chuyee@google.com?part=3D3