Commit f4c848db authored by David S. Miller's avatar David S. Miller

Merge tag 'linux-can-fixes-for-5.12-20210329' of...

Merge tag 'linux-can-fixes-for-5.12-20210329' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can

Marc Kleine-Budde says:

====================
pull-request: can 2021-03-29

this is a pull request of 3 patches for net/master.

The two patch are by Oliver Hartkopp. He fixes length check in the
proto_ops::getname callback for the CAN RAW, BCM and ISOTP protocols,
which were broken by the introduction of the J1939 protocol.

The last patch is by me and fixes the a BUILD_BUG_ON() check which
triggers on ARCH=arm with CONFIG_AEABI unset.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 2dce6987 f5076c6b
...@@ -113,7 +113,7 @@ struct can_frame { ...@@ -113,7 +113,7 @@ struct can_frame {
*/ */
__u8 len; __u8 len;
__u8 can_dlc; /* deprecated */ __u8 can_dlc; /* deprecated */
}; } __attribute__((packed)); /* disable padding added in some ABIs */
__u8 __pad; /* padding */ __u8 __pad; /* padding */
__u8 __res0; /* reserved / padding */ __u8 __res0; /* reserved / padding */
__u8 len8_dlc; /* optional DLC for 8 byte payload length (9 .. 15) */ __u8 len8_dlc; /* optional DLC for 8 byte payload length (9 .. 15) */
......
...@@ -86,6 +86,8 @@ MODULE_LICENSE("Dual BSD/GPL"); ...@@ -86,6 +86,8 @@ MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>"); MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
MODULE_ALIAS("can-proto-2"); MODULE_ALIAS("can-proto-2");
#define BCM_MIN_NAMELEN CAN_REQUIRED_SIZE(struct sockaddr_can, can_ifindex)
/* /*
* easy access to the first 64 bit of can(fd)_frame payload. cp->data is * easy access to the first 64 bit of can(fd)_frame payload. cp->data is
* 64 bit aligned so the offset has to be multiples of 8 which is ensured * 64 bit aligned so the offset has to be multiples of 8 which is ensured
...@@ -1292,7 +1294,7 @@ static int bcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) ...@@ -1292,7 +1294,7 @@ static int bcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
/* no bound device as default => check msg_name */ /* no bound device as default => check msg_name */
DECLARE_SOCKADDR(struct sockaddr_can *, addr, msg->msg_name); DECLARE_SOCKADDR(struct sockaddr_can *, addr, msg->msg_name);
if (msg->msg_namelen < CAN_REQUIRED_SIZE(*addr, can_ifindex)) if (msg->msg_namelen < BCM_MIN_NAMELEN)
return -EINVAL; return -EINVAL;
if (addr->can_family != AF_CAN) if (addr->can_family != AF_CAN)
...@@ -1534,7 +1536,7 @@ static int bcm_connect(struct socket *sock, struct sockaddr *uaddr, int len, ...@@ -1534,7 +1536,7 @@ static int bcm_connect(struct socket *sock, struct sockaddr *uaddr, int len,
struct net *net = sock_net(sk); struct net *net = sock_net(sk);
int ret = 0; int ret = 0;
if (len < CAN_REQUIRED_SIZE(*addr, can_ifindex)) if (len < BCM_MIN_NAMELEN)
return -EINVAL; return -EINVAL;
lock_sock(sk); lock_sock(sk);
...@@ -1616,8 +1618,8 @@ static int bcm_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, ...@@ -1616,8 +1618,8 @@ static int bcm_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
sock_recv_ts_and_drops(msg, sk, skb); sock_recv_ts_and_drops(msg, sk, skb);
if (msg->msg_name) { if (msg->msg_name) {
__sockaddr_check_size(sizeof(struct sockaddr_can)); __sockaddr_check_size(BCM_MIN_NAMELEN);
msg->msg_namelen = sizeof(struct sockaddr_can); msg->msg_namelen = BCM_MIN_NAMELEN;
memcpy(msg->msg_name, skb->cb, msg->msg_namelen); memcpy(msg->msg_name, skb->cb, msg->msg_namelen);
} }
......
...@@ -77,6 +77,8 @@ MODULE_LICENSE("Dual BSD/GPL"); ...@@ -77,6 +77,8 @@ MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("Oliver Hartkopp <socketcan@hartkopp.net>"); MODULE_AUTHOR("Oliver Hartkopp <socketcan@hartkopp.net>");
MODULE_ALIAS("can-proto-6"); MODULE_ALIAS("can-proto-6");
#define ISOTP_MIN_NAMELEN CAN_REQUIRED_SIZE(struct sockaddr_can, can_addr.tp)
#define SINGLE_MASK(id) (((id) & CAN_EFF_FLAG) ? \ #define SINGLE_MASK(id) (((id) & CAN_EFF_FLAG) ? \
(CAN_EFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG) : \ (CAN_EFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG) : \
(CAN_SFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG)) (CAN_SFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG))
...@@ -986,7 +988,8 @@ static int isotp_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, ...@@ -986,7 +988,8 @@ static int isotp_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
sock_recv_timestamp(msg, sk, skb); sock_recv_timestamp(msg, sk, skb);
if (msg->msg_name) { if (msg->msg_name) {
msg->msg_namelen = sizeof(struct sockaddr_can); __sockaddr_check_size(ISOTP_MIN_NAMELEN);
msg->msg_namelen = ISOTP_MIN_NAMELEN;
memcpy(msg->msg_name, skb->cb, msg->msg_namelen); memcpy(msg->msg_name, skb->cb, msg->msg_namelen);
} }
...@@ -1056,7 +1059,7 @@ static int isotp_bind(struct socket *sock, struct sockaddr *uaddr, int len) ...@@ -1056,7 +1059,7 @@ static int isotp_bind(struct socket *sock, struct sockaddr *uaddr, int len)
int notify_enetdown = 0; int notify_enetdown = 0;
int do_rx_reg = 1; int do_rx_reg = 1;
if (len < CAN_REQUIRED_SIZE(struct sockaddr_can, can_addr.tp)) if (len < ISOTP_MIN_NAMELEN)
return -EINVAL; return -EINVAL;
/* do not register frame reception for functional addressing */ /* do not register frame reception for functional addressing */
...@@ -1152,13 +1155,13 @@ static int isotp_getname(struct socket *sock, struct sockaddr *uaddr, int peer) ...@@ -1152,13 +1155,13 @@ static int isotp_getname(struct socket *sock, struct sockaddr *uaddr, int peer)
if (peer) if (peer)
return -EOPNOTSUPP; return -EOPNOTSUPP;
memset(addr, 0, sizeof(*addr)); memset(addr, 0, ISOTP_MIN_NAMELEN);
addr->can_family = AF_CAN; addr->can_family = AF_CAN;
addr->can_ifindex = so->ifindex; addr->can_ifindex = so->ifindex;
addr->can_addr.tp.rx_id = so->rxid; addr->can_addr.tp.rx_id = so->rxid;
addr->can_addr.tp.tx_id = so->txid; addr->can_addr.tp.tx_id = so->txid;
return sizeof(*addr); return ISOTP_MIN_NAMELEN;
} }
static int isotp_setsockopt(struct socket *sock, int level, int optname, static int isotp_setsockopt(struct socket *sock, int level, int optname,
......
...@@ -60,6 +60,8 @@ MODULE_LICENSE("Dual BSD/GPL"); ...@@ -60,6 +60,8 @@ MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("Urs Thuermann <urs.thuermann@volkswagen.de>"); MODULE_AUTHOR("Urs Thuermann <urs.thuermann@volkswagen.de>");
MODULE_ALIAS("can-proto-1"); MODULE_ALIAS("can-proto-1");
#define RAW_MIN_NAMELEN CAN_REQUIRED_SIZE(struct sockaddr_can, can_ifindex)
#define MASK_ALL 0 #define MASK_ALL 0
/* A raw socket has a list of can_filters attached to it, each receiving /* A raw socket has a list of can_filters attached to it, each receiving
...@@ -394,7 +396,7 @@ static int raw_bind(struct socket *sock, struct sockaddr *uaddr, int len) ...@@ -394,7 +396,7 @@ static int raw_bind(struct socket *sock, struct sockaddr *uaddr, int len)
int err = 0; int err = 0;
int notify_enetdown = 0; int notify_enetdown = 0;
if (len < CAN_REQUIRED_SIZE(*addr, can_ifindex)) if (len < RAW_MIN_NAMELEN)
return -EINVAL; return -EINVAL;
if (addr->can_family != AF_CAN) if (addr->can_family != AF_CAN)
return -EINVAL; return -EINVAL;
...@@ -475,11 +477,11 @@ static int raw_getname(struct socket *sock, struct sockaddr *uaddr, ...@@ -475,11 +477,11 @@ static int raw_getname(struct socket *sock, struct sockaddr *uaddr,
if (peer) if (peer)
return -EOPNOTSUPP; return -EOPNOTSUPP;
memset(addr, 0, sizeof(*addr)); memset(addr, 0, RAW_MIN_NAMELEN);
addr->can_family = AF_CAN; addr->can_family = AF_CAN;
addr->can_ifindex = ro->ifindex; addr->can_ifindex = ro->ifindex;
return sizeof(*addr); return RAW_MIN_NAMELEN;
} }
static int raw_setsockopt(struct socket *sock, int level, int optname, static int raw_setsockopt(struct socket *sock, int level, int optname,
...@@ -739,7 +741,7 @@ static int raw_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) ...@@ -739,7 +741,7 @@ static int raw_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
if (msg->msg_name) { if (msg->msg_name) {
DECLARE_SOCKADDR(struct sockaddr_can *, addr, msg->msg_name); DECLARE_SOCKADDR(struct sockaddr_can *, addr, msg->msg_name);
if (msg->msg_namelen < CAN_REQUIRED_SIZE(*addr, can_ifindex)) if (msg->msg_namelen < RAW_MIN_NAMELEN)
return -EINVAL; return -EINVAL;
if (addr->can_family != AF_CAN) if (addr->can_family != AF_CAN)
...@@ -832,8 +834,8 @@ static int raw_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, ...@@ -832,8 +834,8 @@ static int raw_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
sock_recv_ts_and_drops(msg, sk, skb); sock_recv_ts_and_drops(msg, sk, skb);
if (msg->msg_name) { if (msg->msg_name) {
__sockaddr_check_size(sizeof(struct sockaddr_can)); __sockaddr_check_size(RAW_MIN_NAMELEN);
msg->msg_namelen = sizeof(struct sockaddr_can); msg->msg_namelen = RAW_MIN_NAMELEN;
memcpy(msg->msg_name, skb->cb, msg->msg_namelen); memcpy(msg->msg_name, skb->cb, msg->msg_namelen);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment