public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Waiman Long <longman@redhat.com>
To: Andrei Vagin <avagin@gmail.com>
Cc: Andrei Vagin <avagin@google.com>,
	"Matthew Wilcox (Oracle)" <willy@infradead.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
	Boqun Feng <boqun@kernel.org>,
	linux-kernel@vger.kernel.org,
	syzbot+3d2ff92c67127d337463@syzkaller.appspotmail.com
Subject: Re: [PATCH] locking/rwsem: Fix logic error in rwsem_del_waiter()
Date: Tue, 17 Mar 2026 19:39:50 -0400	[thread overview]
Message-ID: <1d3e9ff7-cdd7-4f75-baf0-198ec0ecbf2d@redhat.com> (raw)
In-Reply-To: <CANaxB-y1gVn+oTSyfs9J+ndFCRfvx4_DVBUbbDvUG3bUjW8c6Q@mail.gmail.com>


On 3/17/26 5:23 PM, Andrei Vagin wrote:
> On Mon, Mar 16, 2026 at 12:10 PM Waiman Long <longman@redhat.com> wrote:
>> On 3/16/26 1:49 PM, Waiman Long wrote:
>>> On 3/16/26 1:34 PM, Waiman Long wrote:
>>>> On 3/14/26 2:26 PM, Andrei Vagin wrote:
>>>>> Commit 1ea4b473504b ("locking/rwsem: Remove the list_head from struct
>>>>> rw_semaphore") introduced a logic error in rwsem_del_waiter().
>>>>>
>>>>> The root cause of this issue is an inconsistency in the return
>>>>> values of
>>>>> __rwsem_del_waiter() and rwsem_del_waiter(). Specifically,
>>>>> __rwsem_del_waiter() returns true when the wait list becomes empty,
>>>>> whereas rwsem_del_waiter() is supposed to return true if the wait list
>>>>> is NOT empty.
>>>>>
>>>>> This caused a null pointer dereference in rwsem_mark_wake() because it
>>>>> was being called when sem->first_waiter was NULL.
>>>>>
>>>>> Cc: Matthew Wilcox (Oracle)<willy@infradead.org>
>>>>> Reported-by:syzbot+3d2ff92c67127d337463@syzkaller.appspotmail.com
>>>>> Tested-by:syzbot+3d2ff92c67127d337463@syzkaller.appspotmail.com
>>>>> Fixes: 1ea4b473504b ("locking/rwsem: Remove the list_head from
>>>>> struct rw_semaphore")
>>>>> Signed-off-by: Andrei Vagin<avagin@google.com>
>>>>> ---
>>>>>    kernel/locking/rwsem.c | 4 ++--
>>>>>    1 file changed, 2 insertions(+), 2 deletions(-)
>>>>>
>>>>> diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c
>>>>> index ba4cb74de064..bf647097369c 100644
>>>>> --- a/kernel/locking/rwsem.c
>>>>> +++ b/kernel/locking/rwsem.c
>>>>> @@ -370,7 +370,7 @@ bool __rwsem_del_waiter(struct rw_semaphore
>>>>> *sem, struct rwsem_waiter *waiter)
>>>>>    {
>>>>>        if (list_empty(&waiter->list)) {
>>>>>            sem->first_waiter = NULL;
>>>>> -        return true;
>>>>> +        return false;
>>>>>        }
>>>>>          if (sem->first_waiter == waiter) {
>>>>> @@ -379,7 +379,7 @@ bool __rwsem_del_waiter(struct rw_semaphore
>>>>> *sem, struct rwsem_waiter *waiter)
>>>>>        }
>>>>>        list_del(&waiter->list);
>>>>>    -    return false;
>>>>> +    return true;
>>>>>    }
>>>>>      /*
>>>> It will be better if we also document what does the return value of
>>>> __rwsem_del_waiter() means as the we can't guess from the function
>>>> name itself. Other that that,
>>>>
>>>> Reviewed-by: Waiman Long <longman@redhat.com>
>>>>
>>> Thinking a bit more about it. I think it will be better to not return
>>> a value in __rwsem_del_waiter() at all. Something like
>>>
>> Sorry, my mailer screwed up the diff. It should be as follows.
>>
>> Cheers,
>> Longman
>>
>> =================================[ Cut here ]============================
>> diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c
>> index ba4cb74de064..ce57ad3c1120 100644
>> --- a/kernel/locking/rwsem.c
>> +++ b/kernel/locking/rwsem.c
>> @@ -365,12 +365,11 @@ enum rwsem_wake_type {
>>    #define MAX_READERS_WAKEUP     0x100
>>
>>    static inline
>> -bool __rwsem_del_waiter(struct rw_semaphore *sem, struct rwsem_waiter *waiter)
>> +void __rwsem_del_waiter(struct rw_semaphore *sem, struct rwsem_waiter *waiter)
>>           __must_hold(&sem->wait_lock)
>>    {
>>           if (list_empty(&waiter->list)) {
>>                   sem->first_waiter = NULL;
>> -               return true;
> We still need `return` here.
>
>>           }
>>
>>           if (sem->first_waiter == waiter) {
>> @@ -378,8 +377,6 @@ bool __rwsem_del_waiter(struct rw_semaphore *sem, struct rw>
>>                                                        struct rwsem_waiter, list);
>>           }
>>           list_del(&waiter->list);
>> -
>> -       return false;
>>    }
>>
>>    /*
>> @@ -394,7 +391,8 @@ static inline bool
>>    rwsem_del_waiter(struct rw_semaphore *sem, struct rwsem_waiter *waiter)
>>    {
>>           lockdep_assert_held(&sem->wait_lock);
>> -       if (__rwsem_del_waiter(sem, waiter))
>> +       __rwsem_del_waiter(sem, waiter);
>> +       if (rwsem_is_contended(sem))
> I am ok with this approach too. Do you want to send this patch?

Sure. I will send out later tonight or tomorrow morning.

Cheers,
Longman


  reply	other threads:[~2026-03-17 23:39 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-14 18:26 [PATCH] locking/rwsem: Fix logic error in rwsem_del_waiter() Andrei Vagin
2026-03-16 11:51 ` Peter Zijlstra
     [not found] ` <025cdbad-99e1-4342-9f37-2564c555a8d1@redhat.com>
2026-03-16 17:49   ` Waiman Long
2026-03-16 19:04     ` Waiman Long
2026-03-17 21:23       ` Andrei Vagin
2026-03-17 23:39         ` Waiman Long [this message]
2026-03-18  8:02 ` [tip: locking/core] " tip-bot2 for Andrei Vagin
2026-03-18 16:49   ` Andrei Vagin
2026-03-18 17:15     ` Waiman Long
2026-03-18 20:31     ` Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1d3e9ff7-cdd7-4f75-baf0-198ec0ecbf2d@redhat.com \
    --to=longman@redhat.com \
    --cc=avagin@gmail.com \
    --cc=avagin@google.com \
    --cc=boqun@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=syzbot+3d2ff92c67127d337463@syzkaller.appspotmail.com \
    --cc=will@kernel.org \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox