Commit e0028cec authored by Kuniyuki Iwashima's avatar Kuniyuki Iwashima Committed by sanglipeng
Browse files

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

stable inclusion
from stable-v5.10.195
commit 2e18493c421428a936946c452461b8e979088f17
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I95JOC

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=2e18493c421428a936946c452461b8e979088f17



--------------------------------

[ Upstream commit a22730b1 ]

syzkaller found a memory leak in kcm_sendmsg(), and commit c821a88b
("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.

Fixes: c821a88b ("kcm: Fix memory leak in error path of kcm_sendmsg()")
Fixes: ab7ac4eb ("kcm: Kernel Connection Multiplexor module")
Signed-off-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
Link: https://lore.kernel.org/r/20230912022753.33327-1-kuniyu@amazon.com


Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarsanglipeng <sanglipeng1@jd.com>
parent 747f05e3
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment