This is a note to let you know that I've just added the patch titled mctp: handle the struct sockaddr_mctp padding fields to the 5.15-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: mctp-handle-the-struct-sockaddr_mctp-padding-fields.patch and it can be found in the queue-5.15 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 1e4b50f06d970d8da3474d2a0354450416710bda Mon Sep 17 00:00:00 2001 From: Eugene Syromiatnikov <esyr@xxxxxxxxxx> Date: Wed, 3 Nov 2021 20:09:42 +0100 Subject: mctp: handle the struct sockaddr_mctp padding fields From: Eugene Syromiatnikov <esyr@xxxxxxxxxx> commit 1e4b50f06d970d8da3474d2a0354450416710bda upstream. In order to have the padding fields actually usable in the future, there have to be checks that user space doesn't supply non-zero garbage there. It is also worth setting these padding fields to zero, unless it is known that they have been already zeroed. Cc: stable@xxxxxxxxxxxxxxx # v5.15 Fixes: 5a20dd46b8b84593 ("mctp: Be explicit about struct sockaddr_mctp padding") Signed-off-by: Eugene Syromiatnikov <esyr@xxxxxxxxxx> Acked-by: Jeremy Kerr <jk@xxxxxxxxxxxxxxxxxxxx> Signed-off-by: Jakub Kicinski <kuba@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- net/mctp/af_mctp.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) --- a/net/mctp/af_mctp.c +++ b/net/mctp/af_mctp.c @@ -30,6 +30,12 @@ static int mctp_release(struct socket *s return 0; } +/* Generic sockaddr checks, padding checks only so far */ +static bool mctp_sockaddr_is_ok(const struct sockaddr_mctp *addr) +{ + return !addr->__smctp_pad0 && !addr->__smctp_pad1; +} + static int mctp_bind(struct socket *sock, struct sockaddr *addr, int addrlen) { struct sock *sk = sock->sk; @@ -49,6 +55,9 @@ static int mctp_bind(struct socket *sock /* it's a valid sockaddr for MCTP, cast and do protocol checks */ smctp = (struct sockaddr_mctp *)addr; + if (!mctp_sockaddr_is_ok(smctp)) + return -EINVAL; + lock_sock(sk); /* TODO: allow rebind */ @@ -83,6 +92,8 @@ static int mctp_sendmsg(struct socket *s return -EINVAL; if (addr->smctp_family != AF_MCTP) return -EINVAL; + if (!mctp_sockaddr_is_ok(addr)) + return -EINVAL; if (addr->smctp_tag & ~(MCTP_TAG_MASK | MCTP_TAG_OWNER)) return -EINVAL; @@ -172,11 +183,13 @@ static int mctp_recvmsg(struct socket *s addr = msg->msg_name; addr->smctp_family = AF_MCTP; + addr->__smctp_pad0 = 0; addr->smctp_network = cb->net; addr->smctp_addr.s_addr = hdr->src; addr->smctp_type = type; addr->smctp_tag = hdr->flags_seq_tag & (MCTP_HDR_TAG_MASK | MCTP_HDR_FLAG_TO); + addr->__smctp_pad1 = 0; msg->msg_namelen = sizeof(*addr); } Patches currently in stable-queue which might be from esyr@xxxxxxxxxx are queue-5.15/mctp-handle-the-struct-sockaddr_mctp-padding-fields.patch