From nobody Thu Feb 12 09:09:19 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6375BC77B61 for ; Tue, 25 Apr 2023 18:49:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234692AbjDYSt3 (ORCPT ); Tue, 25 Apr 2023 14:49:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234683AbjDYStL (ORCPT ); Tue, 25 Apr 2023 14:49:11 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D12C916188 for ; Tue, 25 Apr 2023 11:49:06 -0700 (PDT) Message-ID: <20230425183313.143596887@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1682448545; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=me0I7Ik/2QPR1Cxbi2+BttUOdfbhm4wKXX1mgySouMM=; b=BZ/yP6BsoN6Kaono2yFEiQcD9foanNtBqch0FSIVVI7ewIsR2CtkITKpxKcAdGuAptLhEc bIHcVieXzzVpeJ5rG00ec5AyD8hzKv4rhzLlz0u1TpLucVTEGywLAv501vCuOUD59fi06L UxgpWTbGPyqJC6h2kET0SogqxEQ7WZj56KQ2oeT86f/iTrhXgbPdbKvq+iz8NGJx8dqHLc RH+/kF/vj0KkfA63z2OqdXmlLqVzgmJ43vg8442IMkjMytwWJ18j5IsvNHMGB39pTbwMx5 fNPsiDurCMxLhrXAstojRe/B4ATAXCciNan3Vys/w0GdraUakDCrAaEZEAbzbw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1682448545; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=me0I7Ik/2QPR1Cxbi2+BttUOdfbhm4wKXX1mgySouMM=; b=GecTvQlK3AjHVOha7Dld2H5pG/RjVzlGyVF9JQnFpRjNq5woiEBG2gQ+6/wkvMxpc6tDQi 0HM/7nptC6ZwZmDg== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , Peter Zijlstra , Sebastian Siewior , syzbot+5c54bd3eb218bb595aa9@syzkaller.appspotmail.com, Dmitry Vyukov , Michael Kerrisk Subject: [patch 06/20] posix-timers: Annotate concurrent access to k_itimer::it_signal References: <20230425181827.219128101@linutronix.de> MIME-Version: 1.0 Date: Tue, 25 Apr 2023 20:49:05 +0200 (CEST) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" k_itimer::it_signal is read lockless in the RCU protected hash lookup, but it can be written concurrently in the timer_create() and timer_delete() path. Annotate these places with READ_ONCE() and WRITE_ONCE() Signed-off-by: Thomas Gleixner Reviewed-by: Frederic Weisbecker --- kernel/time/posix-timers.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -109,9 +109,9 @@ static struct k_itimer *__posix_timers_f { struct k_itimer *timer; =20 - hlist_for_each_entry_rcu(timer, head, t_hash, - lockdep_is_held(&hash_lock)) { - if ((timer->it_signal =3D=3D sig) && (timer->it_id =3D=3D id)) + hlist_for_each_entry_rcu(timer, head, t_hash, lockdep_is_held(&hash_lock)= ) { + /* timer->it_signal can be set concurrently */ + if ((READ_ONCE(timer->it_signal) =3D=3D sig) && (timer->it_id =3D=3D id)) return timer; } return NULL; @@ -557,7 +557,7 @@ static int do_timer_create(clockid_t whi =20 spin_lock_irq(¤t->sighand->siglock); /* This makes the timer valid in the hash table */ - new_timer->it_signal =3D current->signal; + WRITE_ONCE(new_timer->it_signal, current->signal); list_add(&new_timer->list, ¤t->signal->posix_timers); spin_unlock_irq(¤t->sighand->siglock); =20 @@ -1051,10 +1051,10 @@ SYSCALL_DEFINE1(timer_delete, timer_t, t list_del(&timer->list); spin_unlock(¤t->sighand->siglock); /* - * This keeps any tasks waiting on the spin lock from thinking - * they got something (see the lock code above). + * A concurrent lookup could check timer::it_signal lockless. It + * will reevaluate with timer::it_lock held and observe the NULL. */ - timer->it_signal =3D NULL; + WRITE_ONCE(timer->it_signal, NULL); =20 unlock_timer(timer, flags); release_posix_timer(timer, IT_ID_SET);