pull-request: can 2021-03-29
Subsystems (4)
Marc Kleine-Budde
maintainerHello Jakub, hello David,
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.
regards,
Marc
---
The following changes since commit 1b479fb801602b22512f53c19b1f93a4fc5d5d9d:
drivers/net/wan/hdlc_fr: Fix a double free in pvc_xmit (2021-03-28 18:08:43 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can.git tags/linux-can-fixes-for-5.12-20210329
for you to fetch changes up to f5076c6ba02e8e24c61c40bbf48078929bc0fc79:
can: uapi: can.h: mark union inside struct can_frame packed (2021-03-29 09:51:49 +0200)
----------------------------------------------------------------
linux-can-fixes-for-5.12-20210329
----------------------------------------------------------------
Marc Kleine-Budde (1):
can: uapi: can.h: mark union inside struct can_frame packed
Oliver Hartkopp (2):
can: bcm/raw: fix msg_namelen values depending on CAN_REQUIRED_SIZE
can: isotp: fix msg_namelen values depending on CAN_REQUIRED_SIZE
include/uapi/linux/can.h | 2 +- net/can/bcm.c | 10 ++++++---- net/can/isotp.c | 11 +++++++---- net/can/raw.c | 14 ++++++++------ 4 files changed, 22 insertions(+), 15 deletions(-)
Marc Kleine-Budde
maintainerPATCH 1/3 can: bcm/raw: fix msg_namelen values depending on CAN_REQUIRED_SIZE
From: Oliver Hartkopp <[email protected]>
Since commit f5223e9eee65 ("can: extend sockaddr_can to include j1939 members") the sockaddr_can has been extended in size and a new CAN_REQUIRED_SIZE macro has been introduced to calculate the protocol specific needed size.
The ABI for the msg_name and msg_namelen has not been adapted to the new CAN_REQUIRED_SIZE macro for the other CAN protocols which leads to a problem when an existing binary reads the (increased) struct sockaddr_can in msg_name.
--- net/can/bcm.c | 10 ++++++---- net/can/raw.c | 14 ++++++++------ 2 files changed, 14 insertions(+), 10 deletions(-)
net/can/bcm.c +6 -4
@@ -86,6 +86,8 @@ MODULE_LICENSE("Dual BSD/GPL");MODULE_AUTHOR ("Oliver Hartkopp <[email protected]>" );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 * 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)/* no bound device as default => check 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 ;if (addr->can_family !=AF_CAN )
@@ -1534,7 +1536,7 @@ static int bcm_connect(struct socket *sock, struct sockaddr *uaddr, int len,struct net *net =sock_net (sk);int ret =0 ; -if (len <CAN_REQUIRED_SIZE (*addr, can_ifindex)) +if (len <BCM_MIN_NAMELEN )return -EINVAL ;lock_sock (sk);
@@ -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);if (msg->msg_name) { -__sockaddr_check_size (sizeof (struct sockaddr_can )); - msg->msg_namelen =sizeof (struct sockaddr_can ); +__sockaddr_check_size (BCM_MIN_NAMELEN ); + msg->msg_namelen =BCM_MIN_NAMELEN ;memcpy (msg->msg_name, skb->cb, msg->msg_namelen); }
net/can/raw.c +8 -6
@@ -60,6 +60,8 @@ MODULE_LICENSE("Dual BSD/GPL");MODULE_AUTHOR ("Urs Thuermann <[email protected]>" );MODULE_ALIAS ("can-proto-1" ); +#define RAW_MIN_NAMELEN CAN_REQUIRED_SIZE(struct sockaddr_can, can_ifindex) +#define MASK_ALL 0/* 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)int err =0 ;int notify_enetdown =0 ; -if (len <CAN_REQUIRED_SIZE (*addr, can_ifindex)) +if (len <RAW_MIN_NAMELEN )return -EINVAL ;if (addr->can_family !=AF_CAN )return -EINVAL ;
@@ -475,11 +477,11 @@ static int raw_getname(struct socket *sock, struct sockaddr *uaddr,if (peer)return -EOPNOTSUPP ; -memset (addr,0 ,sizeof (*addr)); +memset (addr,0 ,RAW_MIN_NAMELEN ); addr->can_family =AF_CAN ; addr->can_ifindex = ro->ifindex; -return sizeof (*addr); +return RAW_MIN_NAMELEN ; } 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)if (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 ;if (addr->can_family !=AF_CAN )
@@ -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);if (msg->msg_name) { -__sockaddr_check_size (sizeof (struct sockaddr_can )); - msg->msg_namelen =sizeof (struct sockaddr_can ); +__sockaddr_check_size (RAW_MIN_NAMELEN ); + msg->msg_namelen =RAW_MIN_NAMELEN ;memcpy (msg->msg_name, skb->cb, msg->msg_namelen); }
base-commit: 1b479fb801602b22512f53c19b1f93a4fc5d5d9d
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 2/3 can: isotp: fix msg_namelen values depending on CAN_REQUIRED_SIZE
In reply to Marc Kleine-BuddeFrom: Oliver Hartkopp <[email protected]>
Since commit f5223e9eee65 ("can: extend sockaddr_can to include j1939 members") the sockaddr_can has been extended in size and a new CAN_REQUIRED_SIZE macro has been introduced to calculate the protocol specific needed size.
The ABI for the msg_name and msg_namelen has not been adapted to the new CAN_REQUIRED_SIZE macro for the other CAN protocols which leads to a problem when an existing binary reads the (increased) struct sockaddr_can in msg_name.
--- net/can/isotp.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
net/can/isotp.c +7 -4
@@ -77,6 +77,8 @@ MODULE_LICENSE("Dual BSD/GPL");MODULE_AUTHOR ("Oliver Hartkopp <[email protected]>" );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) ? \ (CAN_EFF_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,sock_recv_timestamp (msg, sk, skb);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); }
@@ -1056,7 +1059,7 @@ static int isotp_bind(struct socket *sock, struct sockaddr *uaddr, int len)int notify_enetdown =0 ;int do_rx_reg =1 ; - if (len < CAN_REQUIRED_SIZE(struct sockaddr_can, can_addr.tp)) +if (len <ISOTP_MIN_NAMELEN )return -EINVAL ;/* do not register frame reception for functional addressing */
@@ -1152,13 +1155,13 @@ static int isotp_getname(struct socket *sock, struct sockaddr *uaddr, int peer)if (peer)return -EOPNOTSUPP ; -memset (addr,0 ,sizeof (*addr)); +memset (addr,0 ,ISOTP_MIN_NAMELEN ); addr->can_family =AF_CAN ; addr->can_ifindex = so->ifindex; addr->can_addr.tp.rx_id = so->rxid; 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,
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerPATCH 3/3 can: uapi: can.h: mark union inside struct can_frame packed
In reply to Marc Kleine-BuddeIn commit ea7800565a12 ("can: add optional DLC element to Classical CAN frame structure") the struct can_frame::can_dlc was put into an anonymous union with another u8 variable.
For various reasons some members in struct can_frame and canfd_frame including the first 8 byes of data are expected to have the same memory layout. This is enforced by a BUILD_BUG_ON check in af_can.c.
Since the above mentioned commit this check fails on ARM kernels compiled with the ARM OABI (which means CONFIG_AEABI not set). In this case -mabi=apcs-gnu is passed to the compiler, which leads to a structure size boundary of 32, instead of 8 compared to CONFIG_AEABI enabled. This means the the union in struct can_frame takes 4 bytes instead of the expected 1.
Rong Chen illustrates the problem with pahole in the ARM OABI case:
| struct can_frame {
| canid_t can_id; /* 0 4 */
| union {
| __u8 len; /* 4 1 */
| __u8 can_dlc; /* 4 1 */
| }; /* 4 4 */
| __u8 __pad; /* 8 1 */
| __u8 __res0; /* 9 1 */
| __u8 len8_dlc; /* 10 1 */
|
| /* XXX 5 bytes hole, try to pack */
|
| __u8 data[8]
| __attribute__((__aligned__(8))); /* 16 8 */
|
| /* size: 24, cachelines: 1, members: 6 */
| /* sum members: 19, holes: 1, sum holes: 5 */
| /* forced alignments: 1, forced holes: 1, sum forced holes: 5 */
| /* last cacheline: 24 bytes */
| } __attribute__((__aligned__(8)));Marking the anonymous union as __attribute__((packed)) fixes the BUILD_BUG_ON problem on these compilers.
--- include/uapi/linux/can.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/uapi/linux/can.h +1 -1
@@ -113,7 +113,7 @@ struct can_frame {*/ __u8 len;__u8 can_dlc;/* deprecated */ - }; + } __attribute__((packed)); /* disable padding added in some ABIs */__u8 __pad;/* padding */ __u8 __res0;/* reserved / padding */ __u8 len8_dlc;/* optional DLC for 8 byte payload length (9 .. 15) */
Signature · 1 line
2.30.2
This pull request was applied to netdev/net.git (refs/heads/master):
Hello:
This pull request was applied to netdev/net.git (refs/heads/master):
Quoted 9 lines · On Mon, 29 Mar 2021 10:53:52 +0200 you wrote:
Hello Jakub, hello David,
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::getnamecallback for the CAN RAW, BCM and ISOTP protocols, which were broken by the introduction of the J1939 protocol.[...]
Here is the summary with links:
- pull-request: can 2021-03-29
https://git.kernel.org/netdev/net/c/f4c848db16be - [net,2/3] can: isotp: fix msg_namelen values depending on CAN_REQUIRED_SIZE https://git.kernel.org/netdev/net/c/f522d9559b07 - [net,3/3] can: uapi: can.h: mark union inside struct can_frame packed https://git.kernel.org/netdev/net/c/f5076c6ba02e
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html