Skip to content

Commit 47f61de

Browse files
committed
can: isotp: isotp_bind(): do not validate unused address information
JIRA: https://issues.redhat.com/browse/RHEL-80832 commit b76b163 Author: Oliver Hartkopp <socketcan@hartkopp.net> Date: Tue May 17 16:56:53 2022 +0200 can: isotp: isotp_bind(): do not validate unused address information With commit 2aa3988 ("can: isotp: isotp_bind(): return -EINVAL on incorrect CAN ID formatting") the bind() syscall returns -EINVAL when the given CAN ID needed to be sanitized. But in the case of an unconfirmed broadcast mode the rx CAN ID is not needed and may be uninitialized from the caller - which is ok. This patch makes sure the result of an inproper CAN ID format is only provided when the address information is needed. Link: https://lore.kernel.org/all/20220517145653.2556-1-socketcan@hartkopp.net Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Radu Rendec <rrendec@redhat.com>
1 parent 0231811 commit 47f61de

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

net/can/isotp.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,31 +1202,36 @@ static int isotp_bind(struct socket *sock, struct sockaddr *uaddr, int len)
12021202
struct net *net = sock_net(sk);
12031203
int ifindex;
12041204
struct net_device *dev;
1205-
canid_t tx_id, rx_id;
1205+
canid_t tx_id = addr->can_addr.tp.tx_id;
1206+
canid_t rx_id = addr->can_addr.tp.rx_id;
12061207
int err = 0;
12071208
int notify_enetdown = 0;
12081209

12091210
if (len < ISOTP_MIN_NAMELEN)
12101211
return -EINVAL;
12111212

1212-
/* sanitize tx/rx CAN identifiers */
1213-
tx_id = addr->can_addr.tp.tx_id;
1213+
/* sanitize tx CAN identifier */
12141214
if (tx_id & CAN_EFF_FLAG)
12151215
tx_id &= (CAN_EFF_FLAG | CAN_EFF_MASK);
12161216
else
12171217
tx_id &= CAN_SFF_MASK;
12181218

1219-
rx_id = addr->can_addr.tp.rx_id;
1220-
if (rx_id & CAN_EFF_FLAG)
1221-
rx_id &= (CAN_EFF_FLAG | CAN_EFF_MASK);
1222-
else
1223-
rx_id &= CAN_SFF_MASK;
1224-
1225-
/* give feedback on wrong CAN-ID values */
1226-
if (tx_id != addr->can_addr.tp.tx_id ||
1227-
rx_id != addr->can_addr.tp.rx_id)
1219+
/* give feedback on wrong CAN-ID value */
1220+
if (tx_id != addr->can_addr.tp.tx_id)
12281221
return -EINVAL;
12291222

1223+
/* sanitize rx CAN identifier (if needed) */
1224+
if (isotp_register_rxid(so)) {
1225+
if (rx_id & CAN_EFF_FLAG)
1226+
rx_id &= (CAN_EFF_FLAG | CAN_EFF_MASK);
1227+
else
1228+
rx_id &= CAN_SFF_MASK;
1229+
1230+
/* give feedback on wrong CAN-ID value */
1231+
if (rx_id != addr->can_addr.tp.rx_id)
1232+
return -EINVAL;
1233+
}
1234+
12301235
if (!addr->can_ifindex)
12311236
return -ENODEV;
12321237

0 commit comments

Comments
 (0)