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=1796183105; b=W8NYpPkIhbL7JmW6Zxok44K9sKvLwoZqfdn9PPJo62une88MCtQOkQOJS0OfD2QTkXSX BKDGZ4YhYTMSiACG2sy0y6Gz29j81erCWu0blPBgktkMI9Iu2lqRq1gvw60dTWfBFQdNR xoI1OP3fkx4IRgatrnXYfgn4RFlp6QN79SK1/hgjhS60M3HonXhFrF/IqwqPWj5rsSnCx H0K0E9eYIvLPbFesd/wN6YinlhAUvhM7UYnc02+7pwwwcYgTm2HgL9z+xQHKxRU6F8Biq S8LZ4lPiK+edPal9Am21wujZeAUF38jQrqeP/9lBj+EQdJ7mb27UvqkVsWiPyhd2p+Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796183105; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=zV3DoU37wsLrpWxbucOScDx0ET/zTNcQ5jOwdigGJ24=; b=yko4PS7biX2MI7WJCWM08/PDRM6tcQQXTMhSgZBa5e8PJQXNyGCNc68KDcmT6SmYt+sS YPWLzs2RHAdhBeEDkkDaFaKpv/frie4Zb3F1sD5BYLKakzZ0rQdsEgOrSOonepbgMcd7A BEITzJ5GbJx4LWRQA2G/ny3c/6Wvfay9shVcZP+kF2omoUuO7dHvzwVw1EUD8ZTOjptcu uvlg8mXjHguzUjTNuYD63Uvja64IAzXqZIft//q6bXIbntvb+yUA+S+cZFssL1Q+lvK7e Fb6vU9upTxEbG7DWX0AIMlcsljksn/QzVVN8qpPG7xE9UKlAQAAW9+LaVeaMBKVPNMA== 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=Acr67H5Y; 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 D64A1606A31A for ; Wed, 2 Dec 2026 03:45:05 +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=Acr67H5Y Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58A951F00899; Wed, 2 Dec 2026 03:45:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796183105; bh=zV3DoU37wsLrpWxbucOScDx0ET/zTNcQ5jOwdigGJ24=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Acr67H5Y003aZvoVBTZpXEUWawvX4n8eeVhnoil+WNOeo9ysQh/FIayM1Li3Q4Koc mGPP7EWo+Gt4ZFdsC66cBx3MiQOdyCSr4yo0wNboEQarPOhRopGitFAZ6+uEQOR2t/ OWhsZAjHVoiJHBhUjcAMy+PgRFKSojRxTOGl/QftBbKlsmXu68Uo0ZNfF6PXvbKr5G d4f5R0AjlUnkPCpSTwHwqAPEUgvB24YO0yr3K7KzTnLDVaTlZvBz4rfi7Uhx59mnXx 5KBY+13uguDYaEkjrSFheiBB0mtKj1jJWDcSouRZUyRmokAM0mOdjpLvX4EkXMQjwM nFbwIg54OQlSQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] rv: Synchronize per-object storage hash table and fix exit cleanup Reply-To: sashiko-reviews@lists.linux.dev To: "Hu Xinyao" Cc: linux-trace-kernel@vger.kernel.org In-Reply-To: References: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 03:45:04 +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 2 potential issues to consider: - [High] rv: deferred reset in da_destroy_storage() leaves HA timer armed on exit - [Medium] rv: TOCTOU race on PF_EXITING in handle_sys_enter() leaks dangling target -- commit e1aa8fb39dc01486d1f10cf191d5e9abefc77a07 Author: Hu Xinyao rv: Synchronize per-object storage hash table and fix exit cleanup This commit serializes da_monitor_ht updates with a spinlock, defers per-object monitor reset and teardown via RCU, and updates exit and syscall entry handling in the deadline and nomiss monitors. > diff --git a/include/rv/da_monitor.h b/include/rv/da_monitor.h > index 6fc5ef8142aca..5c3cc9ab91a65 100644 > --- a/include/rv/da_monitor.h > +++ b/include/rv/da_monitor.h [ ... ] > @@ -540,31 +574,43 @@ static inline monitor_target da_get_target_by_id(da= _id_type id) > =20 > if (unlikely(!mon_storage)) > return NULL; > - return mon_storage->target; > + return READ_ONCE(mon_storage->target); > +} > + > +static void __maybe_unused da_destroy_storage_rcu(struct rcu_head *rcu) > +{ > + struct da_monitor_storage *mon_storage =3D > + container_of(rcu, struct da_monitor_storage, rcu); > + > + da_monitor_reset(&mon_storage->rv.da_mon); > + kfree_rcu(mon_storage, rcu); > } > =20 > /* > * da_destroy_storage - destroy the per-object storage > * > - * The caller is responsible to synchronise writers, either with locks or > - * implicitly. For instance, if da_destroy_storage is called at sched_ex= it and > - * da_create_storage can never occur after that, it's safe to call this = without > - * locks. > * This function includes an RCU read-side critical section to synchroni= se > - * against da_monitor_destroy(). > + * against da_monitor_destroy(), and defers resetting/freeing until afte= r RCU > + * grace periods so in-flight readers cannot re-arm HA timers after tear= down. > */ > static inline void da_destroy_storage(da_id_type id) > { > - struct da_monitor_storage *mon_storage; > + struct da_monitor_storage *mon_storage =3D NULL; > =20 > guard(rcu)(); > - mon_storage =3D __da_get_mon_storage(id); > + if (!__da_get_mon_storage(id)) > + return; > + > + scoped_guard(raw_spinlock_irqsave, &da_monitor_ht_lock) { > + mon_storage =3D __da_get_mon_storage_locked(id); > + if (mon_storage) > + hash_del_rcu(&mon_storage->node); > + } > =20 > if (!mon_storage) > return; > - da_monitor_reset_hook(&mon_storage->rv.da_mon); > - hash_del_rcu(&mon_storage->node); > - kfree_rcu(mon_storage, rcu); > + > + call_rcu(&mon_storage->rcu, da_destroy_storage_rcu); > } [Severity: High] Does deferring da_monitor_reset() to da_destroy_storage_rcu() without also resetting synchronously in da_destroy_storage() leave ha_mon->timer armed across the RCU grace period when an active SCHED_DEADLINE task exits? When a running deadline task calls do_exit(), trace_sched_process_exit() runs handle_exit() -> da_destroy_storage() while the task is still on the CPU in state running_nomiss with ha_mon->timer armed. Because da_destroy_storage() unhashes mon_storage without resetting it, the later __schedule() in do_task_dead() cannot find the monitor to deliver sched_switch_suspend_nomiss and cancel the timer. If the task's deadline expires before the RCU grace period finishes, __ha_monitor_timer_callback() sees da_mon.monitoring still set, fires a false-positive deadline miss via ha_react(), and dereferences ha_get_target(ha_mon) (&p->dl), which can also race with delayed_put_task_struct() freeing p in the same RCU grace period (use-after-free). Calling da_monitor_reset(&mon_storage->rv.da_mon) synchronously after unhashing mon_storage, in addition to the reset in da_destroy_storage_rcu(), would cancel the timer on exit while still catching any timer re-armed by an in-flight reader. > diff --git a/kernel/trace/rv/monitors/nomiss/nomiss.c b/kernel/trace/rv/m= onitors/nomiss/nomiss.c > index 6e47d379f7770..248cc14beab4a 100644 > --- a/kernel/trace/rv/monitors/nomiss/nomiss.c > +++ b/kernel/trace/rv/monitors/nomiss/nomiss.c > @@ -194,7 +194,8 @@ static void handle_sys_enter(void *data, struct pt_re= gs *regs, long id) > return; > guard(rcu)(); > p =3D pid ? find_task_by_vpid(pid) : current; > - if (unlikely(!p) || new_policy =3D=3D p->policy) > + if (unlikely(!p) || (READ_ONCE(p->flags) & PF_EXITING) || > + new_policy =3D=3D p->policy) > return; > =20 > if (p->policy =3D=3D SCHED_DEADLINE) [Severity: Medium] Can a target task (pid !=3D 0) enter do_exit() after handle_sys_enter() checks PF_EXITING but before __da_insert_storage() inserts mon_storage, leaving a dangling target pointer in da_monitor_ht? CPU0 CPU1 (task p) handle_sys_enter() p =3D find_task_by_vpid(pid) !(p->flags & PF_EXITING) da_create_or_get(p->pid, &p->dl) ... kmalloc_nolock(...) do_exit() exit_signals(p) p->flags |=3D PF_EXITING trace_sched_process_exit(p, ...) handle_exit() da_destroy_storage(p->pid) /* not in da_monitor_ht */ lock(&da_monitor_ht_lock) hash_add_rcu(..., &mon_storage->node, p->pid) unlock(&da_monitor_ht_lock) ... delayed_put_task_struct() free_task(p) /* later, after p->pid is reused */ handle_sched_switch() ... ha_get_env() ha_get_target(ha_mon)->dl_defer <-- use-after-free When p->pid is later reused by a new task that enters SCHED_DEADLINE, da_create_or_get() finds the leaked mon_storage via da_get_monitor() and da_create_storage() returns early because da_mon is non-NULL, bypassing the existing->target update in __da_insert_storage(). Because mon_storage->target is already non-NULL, da_fill_empty_storage() does not overwrite it either, so subsequent nomiss events dereference the freed task_struct. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/DD5EA120CBEA8D43+17= 96182228.53654-1-huxinyao@kylinsec.com.cn?part=3D1