History

kcm: Fix error handling for SOCK_DGRAM in kcm_sendmsg().

syzkaller found a memory leak in kcm_sendmsg(), and commit c821a88bd720 ("kcm: Fix memory leak in error path of kcm_sendmsg()") suppressed it by updating kcm_tx_msg(head)->last_skb if partial data is copied so that the following sendmsg() will resume from the skb. However, we cannot know how many bytes were copied when we get the error. Thus, we could mess up the MSG_MORE queue. When kcm_sendmsg() fails for SOCK_DGRAM, we should purge the queue as we do so for UDP by udp_flush_pending_frames(). Even without this change, when the error occurred, the following sendmsg() resumed from a wrong skb and the queue was messed up. However, we have yet to get such a report, and only syzkaller stumbled on it. So, this can be changed safely. Note this does not change SOCK_SEQPACKET behaviour.

Kuniyuki Iwashima committed 3 years ago

Commit a22730b1 parent 96f7dc61 file · +8 −7Browse files

Unified · Split

net/kcm/kcmsock.c+8−7
@@ -930,17 +930,18 @@ partial_message: · 929 unmodified lines
930930 out_error:
931931 kcm_push(kcm);
932932
933− if (copied && sock->type == SOCK_SEQPACKET) {
933+ if (sock->type == SOCK_SEQPACKET) {
934934 /* Wrote some bytes before encountering an
935935 * error, return partial success.
936936 */
937− goto partial_message;
938− }
939−
940− if (head != kcm->seq_skb)
937+ if (copied)
938+ goto partial_message;
939+ if (head != kcm->seq_skb)
940+ kfree_skb(head);
941+ } else {
941942 kfree_skb(head);
942− else if (copied)
943− kcm_tx_msg(head)->last_skb = skb;
943+ kcm->seq_skb = NULL;
944+ }
944945
945946 err = sk_stream_error(sk, msg->msg_flags, err);
946947

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t