]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
llc: fix data loss when reading from a socket in llc_ui_recvmsg()
authorIlia Gavrilov <Ilia.Gavrilov@infotecs.ru>
Thu, 15 May 2025 12:20:15 +0000 (12:20 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 4 Jun 2025 12:38:06 +0000 (14:38 +0200)
commit 239af1970bcb039a1551d2c438d113df0010c149 upstream.

For SOCK_STREAM sockets, if user buffer size (len) is less
than skb size (skb->len), the remaining data from skb
will be lost after calling kfree_skb().

To fix this, move the statement for partial reading
above skb deletion.

Found by InfoTeCS on behalf of Linux Verification Center (linuxtesting.org)

Fixes: 30a584d944fb ("[LLX]: SOCK_DGRAM interface fixes")
Cc: stable@vger.kernel.org
Signed-off-by: Ilia Gavrilov <Ilia.Gavrilov@infotecs.ru>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/llc/af_llc.c

index 70973bf18ee333bcc736a0b711c4efd3f1d5a270..0be9dbf38fe7da40fe05f23b2b10c63daf2fb772 100644 (file)
@@ -886,15 +886,15 @@ static int llc_ui_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
                if (sk->sk_type != SOCK_STREAM)
                        goto copy_uaddr;
 
+               /* Partial read */
+               if (used + offset < skb_len)
+                       continue;
+
                if (!(flags & MSG_PEEK)) {
                        skb_unlink(skb, &sk->sk_receive_queue);
                        kfree_skb(skb);
                        *seq = 0;
                }
-
-               /* Partial read */
-               if (used + offset < skb_len)
-                       continue;
        } while (len > 0);
 
 out: