Commit 364642ae authored by David S. Miller's avatar David S. Miller

Merge tag 'linux-can-fixes-for-5.13-20210512' of...

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

Marc Kleine-Budde says:

====================
pull-request: can 2021-05-12

this is a pull request of a single patch for net/master.

The patch is by Norbert Slusarek and it fixes a race condition in the
CAN ISO-TP socket between isotp_bind() and isotp_setsockopt().
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 9c1bb37f 2b17c400
...@@ -1062,27 +1062,31 @@ static int isotp_bind(struct socket *sock, struct sockaddr *uaddr, int len) ...@@ -1062,27 +1062,31 @@ static int isotp_bind(struct socket *sock, struct sockaddr *uaddr, int len)
if (len < ISOTP_MIN_NAMELEN) if (len < ISOTP_MIN_NAMELEN)
return -EINVAL; return -EINVAL;
if (addr->can_addr.tp.tx_id & (CAN_ERR_FLAG | CAN_RTR_FLAG))
return -EADDRNOTAVAIL;
if (!addr->can_ifindex)
return -ENODEV;
lock_sock(sk);
/* do not register frame reception for functional addressing */ /* do not register frame reception for functional addressing */
if (so->opt.flags & CAN_ISOTP_SF_BROADCAST) if (so->opt.flags & CAN_ISOTP_SF_BROADCAST)
do_rx_reg = 0; do_rx_reg = 0;
/* do not validate rx address for functional addressing */ /* do not validate rx address for functional addressing */
if (do_rx_reg) { if (do_rx_reg) {
if (addr->can_addr.tp.rx_id == addr->can_addr.tp.tx_id) if (addr->can_addr.tp.rx_id == addr->can_addr.tp.tx_id) {
return -EADDRNOTAVAIL; err = -EADDRNOTAVAIL;
goto out;
}
if (addr->can_addr.tp.rx_id & (CAN_ERR_FLAG | CAN_RTR_FLAG)) if (addr->can_addr.tp.rx_id & (CAN_ERR_FLAG | CAN_RTR_FLAG)) {
return -EADDRNOTAVAIL; err = -EADDRNOTAVAIL;
goto out;
}
} }
if (addr->can_addr.tp.tx_id & (CAN_ERR_FLAG | CAN_RTR_FLAG))
return -EADDRNOTAVAIL;
if (!addr->can_ifindex)
return -ENODEV;
lock_sock(sk);
if (so->bound && addr->can_ifindex == so->ifindex && if (so->bound && 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)
...@@ -1164,16 +1168,13 @@ static int isotp_getname(struct socket *sock, struct sockaddr *uaddr, int peer) ...@@ -1164,16 +1168,13 @@ static int isotp_getname(struct socket *sock, struct sockaddr *uaddr, int peer)
return ISOTP_MIN_NAMELEN; return ISOTP_MIN_NAMELEN;
} }
static int isotp_setsockopt(struct socket *sock, int level, int optname, static int isotp_setsockopt_locked(struct socket *sock, int level, int optname,
sockptr_t optval, unsigned int optlen) sockptr_t optval, unsigned int optlen)
{ {
struct sock *sk = sock->sk; struct sock *sk = sock->sk;
struct isotp_sock *so = isotp_sk(sk); struct isotp_sock *so = isotp_sk(sk);
int ret = 0; int ret = 0;
if (level != SOL_CAN_ISOTP)
return -EINVAL;
if (so->bound) if (so->bound)
return -EISCONN; return -EISCONN;
...@@ -1248,6 +1249,22 @@ static int isotp_setsockopt(struct socket *sock, int level, int optname, ...@@ -1248,6 +1249,22 @@ static int isotp_setsockopt(struct socket *sock, int level, int optname,
return ret; return ret;
} }
static int isotp_setsockopt(struct socket *sock, int level, int optname,
sockptr_t optval, unsigned int optlen)
{
struct sock *sk = sock->sk;
int ret;
if (level != SOL_CAN_ISOTP)
return -EINVAL;
lock_sock(sk);
ret = isotp_setsockopt_locked(sock, level, optname, optval, optlen);
release_sock(sk);
return ret;
}
static int isotp_getsockopt(struct socket *sock, int level, int optname, static int isotp_getsockopt(struct socket *sock, int level, int optname,
char __user *optval, int __user *optlen) char __user *optval, int __user *optlen)
{ {
......
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