mctp: handle the struct sockaddr_mctp padding fields
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@vger.kernel.org # v5.15
Fixes: 5a20dd46b8
("mctp: Be explicit about struct sockaddr_mctp padding")
Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
Acked-by: Jeremy Kerr <jk@codeconstruct.com.au>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
a5bda90884
commit
1e4b50f06d
|
@ -33,6 +33,12 @@ static int mctp_release(struct socket *sock)
|
||||||
return 0;
|
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)
|
static int mctp_bind(struct socket *sock, struct sockaddr *addr, int addrlen)
|
||||||
{
|
{
|
||||||
struct sock *sk = sock->sk;
|
struct sock *sk = sock->sk;
|
||||||
|
@ -52,6 +58,9 @@ static int mctp_bind(struct socket *sock, struct sockaddr *addr, int addrlen)
|
||||||
/* it's a valid sockaddr for MCTP, cast and do protocol checks */
|
/* it's a valid sockaddr for MCTP, cast and do protocol checks */
|
||||||
smctp = (struct sockaddr_mctp *)addr;
|
smctp = (struct sockaddr_mctp *)addr;
|
||||||
|
|
||||||
|
if (!mctp_sockaddr_is_ok(smctp))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
lock_sock(sk);
|
lock_sock(sk);
|
||||||
|
|
||||||
/* TODO: allow rebind */
|
/* TODO: allow rebind */
|
||||||
|
@ -87,6 +96,8 @@ static int mctp_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (addr->smctp_family != AF_MCTP)
|
if (addr->smctp_family != AF_MCTP)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
if (!mctp_sockaddr_is_ok(addr))
|
||||||
|
return -EINVAL;
|
||||||
if (addr->smctp_tag & ~(MCTP_TAG_MASK | MCTP_TAG_OWNER))
|
if (addr->smctp_tag & ~(MCTP_TAG_MASK | MCTP_TAG_OWNER))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
@ -198,11 +209,13 @@ static int mctp_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
|
||||||
|
|
||||||
addr = msg->msg_name;
|
addr = msg->msg_name;
|
||||||
addr->smctp_family = AF_MCTP;
|
addr->smctp_family = AF_MCTP;
|
||||||
|
addr->__smctp_pad0 = 0;
|
||||||
addr->smctp_network = cb->net;
|
addr->smctp_network = cb->net;
|
||||||
addr->smctp_addr.s_addr = hdr->src;
|
addr->smctp_addr.s_addr = hdr->src;
|
||||||
addr->smctp_type = type;
|
addr->smctp_type = type;
|
||||||
addr->smctp_tag = hdr->flags_seq_tag &
|
addr->smctp_tag = hdr->flags_seq_tag &
|
||||||
(MCTP_HDR_TAG_MASK | MCTP_HDR_FLAG_TO);
|
(MCTP_HDR_TAG_MASK | MCTP_HDR_FLAG_TO);
|
||||||
|
addr->__smctp_pad1 = 0;
|
||||||
msg->msg_namelen = sizeof(*addr);
|
msg->msg_namelen = sizeof(*addr);
|
||||||
|
|
||||||
if (msk->addr_ext) {
|
if (msk->addr_ext) {
|
||||||
|
|
Loading…
Reference in New Issue