# Re: \[PATCH net-next v3\] af\_unix: Fix use-after-free crashes

- From: Eric Dumazet \<hidden\>
- Date: 2011-09-09 06:51:48 
- List: netdev
- Page: https://ratatoskr.run/netdev/2011/09/10878652
- Thread: https://ratatoskr.run/netdev/2011/09/10878569/t.md

```text
Le jeudi 08 septembre 2011 à 01:37 -0700, Tim Chen a écrit :
> On Thu, 2011-09-08 at 15:21 +0200, Eric Dumazet wrote:
> > Le jeudi 08 septembre 2011 à 11:59 +0200, Sedat Dilek a écrit :
> > 
> > > I have tested this fixup patch on i386.
> > > Can we have a separate patch with corrected descriptive text?
> > > 
> > > Thanks to all involved people.
> > 
> > Here it is :
> > 
> > [PATCH net-next v3] af_unix: Fix use-after-free crashes
> > 
> > Commit 0856a30409 (Scm: Remove unnecessary pid & credential references
> > in Unix socket's send and receive path) introduced an use-after-free
> > bug.
> > 
> > We are allowed to steal the references to pid/cred only in the last skb
> > sent from unix_stream_sendmsg(), because first skbs might be consumed by
> > the receiver before we finish our sendmsg() call.
> > 
> > Remove scm_release() helper, since its cleaner to clear pid/cred fields
> > in unix_scm_to_skb() when we steal them.
> > 
> > Based on prior patches from Yan Zheng and Tim Chen
> > 
> > Signed-off-by: Eric Dumazet <redacted>
> > Reported-by: Jiri Slaby <redacted>
> > Tested-by: Sedat Dilek <redacted>
> > Tested-by: Valdis Kletnieks <redacted>
> > ---
> 
> Thanks.
> 
> Acked-by: Tim Chen <redacted>
> 

Now we have to fix a bug in unix_stream_recvmsg() as well.

consume_skb() call actually releases pid/cred references, and we can use
them after their eventual freeing.

Keep also in mind that receiver can provides a too short user buffer,
and skb can be put back to head of sk_receive_queue

Tim, your 0856a304091b33 commit introduced a lot of bugs, I was right
asking a revert.

If we revert your patch, my litle patch (af_unix: dont send
SCM_CREDENTIALS by default) is enough to solve performance problems.
```
