@@ -622,7 +622,9 @@ static void unix_write_space(struct sock *sk)
622
622
static void unix_dgram_disconnected (struct sock * sk , struct sock * other )
623
623
{
624
624
if (!skb_queue_empty (& sk -> sk_receive_queue )) {
625
- skb_queue_purge (& sk -> sk_receive_queue );
625
+ skb_queue_purge_reason (& sk -> sk_receive_queue ,
626
+ SKB_DROP_REASON_UNIX_DISCONNECT );
627
+
626
628
wake_up_interruptible_all (& unix_sk (sk )-> peer_wait );
627
629
628
630
/* If one link of bidirectional dgram pipe is disconnected,
@@ -640,7 +642,7 @@ static void unix_sock_destructor(struct sock *sk)
640
642
{
641
643
struct unix_sock * u = unix_sk (sk );
642
644
643
- skb_queue_purge (& sk -> sk_receive_queue );
645
+ skb_queue_purge_reason (& sk -> sk_receive_queue , SKB_DROP_REASON_SOCKET_CLOSE );
644
646
645
647
DEBUG_NET_WARN_ON_ONCE (refcount_read (& sk -> sk_wmem_alloc ));
646
648
DEBUG_NET_WARN_ON_ONCE (!sk_unhashed (sk ));
@@ -715,8 +717,8 @@ static void unix_release_sock(struct sock *sk, int embrion)
715
717
if (state == TCP_LISTEN )
716
718
unix_release_sock (skb -> sk , 1 );
717
719
718
- /* passed fds are erased in the kfree_skb hook */
719
- kfree_skb (skb );
720
+ /* passed fds are erased in the kfree_skb hook */
721
+ kfree_skb_reason (skb , SKB_DROP_REASON_SOCKET_CLOSE );
720
722
}
721
723
722
724
if (path .dentry )
@@ -1699,7 +1701,7 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
1699
1701
unix_state_unlock (other );
1700
1702
sock_put (other );
1701
1703
out_free_skb :
1702
- kfree_skb (skb );
1704
+ consume_skb (skb );
1703
1705
out_free_sk :
1704
1706
unix_release_sock (newsk , 0 );
1705
1707
out :
@@ -2170,7 +2172,7 @@ static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,
2170
2172
out_sock_put :
2171
2173
sock_put (other );
2172
2174
out_free :
2173
- kfree_skb (skb );
2175
+ consume_skb (skb );
2174
2176
out :
2175
2177
scm_destroy (& scm );
2176
2178
return err ;
@@ -2187,33 +2189,30 @@ static int queue_oob(struct socket *sock, struct msghdr *msg, struct sock *other
2187
2189
{
2188
2190
struct unix_sock * ousk = unix_sk (other );
2189
2191
struct sk_buff * skb ;
2190
- int err = 0 ;
2192
+ int err ;
2191
2193
2192
2194
skb = sock_alloc_send_skb (sock -> sk , 1 , msg -> msg_flags & MSG_DONTWAIT , & err );
2193
2195
2194
2196
if (!skb )
2195
2197
return err ;
2196
2198
2197
2199
err = unix_scm_to_skb (scm , skb , !fds_sent );
2198
- if (err < 0 ) {
2199
- kfree_skb (skb );
2200
- return err ;
2201
- }
2200
+ if (err < 0 )
2201
+ goto out ;
2202
+
2202
2203
skb_put (skb , 1 );
2203
2204
err = skb_copy_datagram_from_iter (skb , 0 , & msg -> msg_iter , 1 );
2204
2205
2205
- if (err ) {
2206
- kfree_skb (skb );
2207
- return err ;
2208
- }
2206
+ if (err )
2207
+ goto out ;
2209
2208
2210
2209
unix_state_lock (other );
2211
2210
2212
2211
if (sock_flag (other , SOCK_DEAD ) ||
2213
2212
(other -> sk_shutdown & RCV_SHUTDOWN )) {
2214
2213
unix_state_unlock (other );
2215
- kfree_skb ( skb ) ;
2216
- return - EPIPE ;
2214
+ err = - EPIPE ;
2215
+ goto out ;
2217
2216
}
2218
2217
2219
2218
maybe_add_creds (skb , sock , other );
@@ -2228,6 +2227,9 @@ static int queue_oob(struct socket *sock, struct msghdr *msg, struct sock *other
2228
2227
unix_state_unlock (other );
2229
2228
other -> sk_data_ready (other );
2230
2229
2230
+ return 0 ;
2231
+ out :
2232
+ consume_skb (skb );
2231
2233
return err ;
2232
2234
}
2233
2235
#endif
@@ -2236,13 +2238,11 @@ static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,
2236
2238
size_t len )
2237
2239
{
2238
2240
struct sock * sk = sock -> sk ;
2241
+ struct sk_buff * skb = NULL ;
2239
2242
struct sock * other = NULL ;
2240
- int err , size ;
2241
- struct sk_buff * skb ;
2242
- int sent = 0 ;
2243
2243
struct scm_cookie scm ;
2244
2244
bool fds_sent = false;
2245
- int data_len ;
2245
+ int err , sent = 0 ;
2246
2246
2247
2247
err = scm_send (sock , msg , & scm , false);
2248
2248
if (err < 0 )
@@ -2271,16 +2271,12 @@ static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,
2271
2271
}
2272
2272
}
2273
2273
2274
- if (READ_ONCE (sk -> sk_shutdown ) & SEND_SHUTDOWN ) {
2275
- if (!(msg -> msg_flags & MSG_NOSIGNAL ))
2276
- send_sig (SIGPIPE , current , 0 );
2277
-
2278
- err = - EPIPE ;
2279
- goto out_err ;
2280
- }
2274
+ if (READ_ONCE (sk -> sk_shutdown ) & SEND_SHUTDOWN )
2275
+ goto out_pipe ;
2281
2276
2282
2277
while (sent < len ) {
2283
- size = len - sent ;
2278
+ int size = len - sent ;
2279
+ int data_len ;
2284
2280
2285
2281
if (unlikely (msg -> msg_flags & MSG_SPLICE_PAGES )) {
2286
2282
skb = sock_alloc_send_pskb (sk , 0 , 0 ,
@@ -2333,7 +2329,7 @@ static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,
2333
2329
2334
2330
if (sock_flag (other , SOCK_DEAD ) ||
2335
2331
(other -> sk_shutdown & RCV_SHUTDOWN ))
2336
- goto out_pipe ;
2332
+ goto out_pipe_unlock ;
2337
2333
2338
2334
maybe_add_creds (skb , sock , other );
2339
2335
scm_stat_add (other , skb );
@@ -2356,13 +2352,14 @@ static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,
2356
2352
2357
2353
return sent ;
2358
2354
2359
- out_pipe :
2355
+ out_pipe_unlock :
2360
2356
unix_state_unlock (other );
2357
+ out_pipe :
2361
2358
if (!sent && !(msg -> msg_flags & MSG_NOSIGNAL ))
2362
2359
send_sig (SIGPIPE , current , 0 );
2363
2360
err = - EPIPE ;
2364
2361
out_free :
2365
- kfree_skb (skb );
2362
+ consume_skb (skb );
2366
2363
out_err :
2367
2364
scm_destroy (& scm );
2368
2365
return sent ? : err ;
@@ -2695,7 +2692,7 @@ static struct sk_buff *manage_oob(struct sk_buff *skb, struct sock *sk,
2695
2692
spin_unlock (& sk -> sk_receive_queue .lock );
2696
2693
2697
2694
consume_skb (read_skb );
2698
- kfree_skb (unread_skb );
2695
+ kfree_skb_reason (unread_skb , SKB_DROP_REASON_UNIX_SKIP_OOB );
2699
2696
2700
2697
return skb ;
2701
2698
}
@@ -2724,7 +2721,7 @@ static int unix_stream_read_skb(struct sock *sk, skb_read_actor_t recv_actor)
2724
2721
2725
2722
if (sock_flag (sk , SOCK_DEAD )) {
2726
2723
unix_state_unlock (sk );
2727
- kfree_skb (skb );
2724
+ kfree_skb_reason (skb , SKB_DROP_REASON_SOCKET_CLOSE );
2728
2725
return - ECONNRESET ;
2729
2726
}
2730
2727
@@ -2738,7 +2735,7 @@ static int unix_stream_read_skb(struct sock *sk, skb_read_actor_t recv_actor)
2738
2735
unix_state_unlock (sk );
2739
2736
2740
2737
if (drop ) {
2741
- kfree_skb (skb );
2738
+ kfree_skb_reason (skb , SKB_DROP_REASON_UNIX_SKIP_OOB );
2742
2739
return - EAGAIN ;
2743
2740
}
2744
2741
}
0 commit comments