Skip to contentSkip to conversation

af_unix: missing lock releases in af_unix.c

PATCH Shoaib Rao 2 participants 2 messages Jan 3, 2022 – Jan 5, 2022 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

Shoaib Rao

author
#1 lore raw
In reply to a message not in the archive
Quoted 12 lines · Ryan Cai

In method __unix_dgram_recvmsg, the lock u->iolock is not released when skb is true and loop breaks.

---
  net/unix/af_unix.c | 1 +
  1 file changed, 1 insertion(+)
net/unix/af_unix.c +0 -0
index b0bfc78e421c..b97972948d9d 100644

net/unix/af_unix.c int __unix_dgram_recvmsg(struct sock *sk, struct msghdr *msg, size_t size, · line 2311

Quoted 7 lines
net/unix/af_unix.c +1 -0
@@ -2305,6 +2305,7 @@ int __unix_dgram_recvmsg(struct sock *sk, struct msghdr *msg, size_t size,
  		if (skb) {
  			if (!(flags & MSG_PEEK))
  				scm_stat_del(sk, skb);
+			mutex_unlock(&u->iolock);
  			break;
  		}
 

It seems to me that the unlock at the end will release the mutex?

out_free:
        skb_free_datagram(sk, skb);
        mutex_unlock(&u->iolock);

Shoaib

#2 lore raw

Hi, Shoaib

After further checking, the lock is indeed released at the out_free. My patch is invalid. Sorry for the inconvenience.

Best,
Ryan

On 4/1/2022, 2:47 AM, "Shoaib Rao" <[email protected]> wrote:

    On 1/3/22 05:58, Ryan Cai wrote:
    > In method __unix_dgram_recvmsg, the lock u->iolock is not released when skb is true and loop breaks.
    >
    > Signed-off-by: Ryan Cai <[email protected]>
    > ---
    >   net/unix/af_unix.c | 1 +
    >   1 file changed, 1 insertion(+)
    >
    > diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
    > index b0bfc78e421c..b97972948d9d 100644
    > --- a/net/unix/af_unix.c
    > +++ b/net/unix/af_unix.c
    > @@ -2305,6 +2305,7 @@ int __unix_dgram_recvmsg(struct sock *sk, struct msghdr *msg, size_t size,
    >   		if (skb) {
    >   			if (!(flags & MSG_PEEK))
    >   				scm_stat_del(sk, skb);
    > +			mutex_unlock(&u->iolock);
    >   			break;
    >   		}
    >   

    It seems to me that the unlock at the end will release the mutex?

    out_free:
             skb_free_datagram(sk, skb);
             mutex_unlock(&u->iolock);

    Shoaib