* pull-request: can 2021-05-12
@ 2021-05-12 7:10 Marc Kleine-Budde
2021-05-12 7:10 ` [net] can: isotp: prevent race between isotp_bind() and isotp_setsockopt() Marc Kleine-Budde
2021-05-12 21:20 ` pull-request: can 2021-05-12 patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Marc Kleine-Budde @ 2021-05-12 7:10 UTC (permalink / raw)
To: netdev; +Cc: davem, kuba, linux-can, kernel
Hello Jakub, hello David,
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().
regards,
Marc
---
The following changes since commit 440c3247cba3d9433ac435d371dd7927d68772a7:
net: ipa: memory region array is variable size (2021-05-11 16:22:37 -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.13-20210512
for you to fetch changes up to 2b17c400aeb44daf041627722581ade527bb3c1d:
can: isotp: prevent race between isotp_bind() and isotp_setsockopt() (2021-05-12 08:52:47 +0200)
----------------------------------------------------------------
linux-can-fixes-for-5.13-20210512
----------------------------------------------------------------
Norbert Slusarek (1):
can: isotp: prevent race between isotp_bind() and isotp_setsockopt()
net/can/isotp.c | 49 +++++++++++++++++++++++++++++++++----------------
1 file changed, 33 insertions(+), 16 deletions(-)
^ permalink raw reply [flat|nested] 3+ messages in thread
* [net] can: isotp: prevent race between isotp_bind() and isotp_setsockopt()
2021-05-12 7:10 pull-request: can 2021-05-12 Marc Kleine-Budde
@ 2021-05-12 7:10 ` Marc Kleine-Budde
2021-05-12 21:20 ` pull-request: can 2021-05-12 patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Marc Kleine-Budde @ 2021-05-12 7:10 UTC (permalink / raw)
To: netdev
Cc: davem, kuba, linux-can, kernel, Norbert Slusarek,
Thadeu Lima de Souza Cascardo, Oliver Hartkopp,
Marc Kleine-Budde
From: Norbert Slusarek <nslusarek@gmx.net>
A race condition was found in isotp_setsockopt() which allows to
change socket options after the socket was bound.
For the specific case of SF_BROADCAST support, this might lead to possible
use-after-free because can_rx_unregister() is not called.
Checking for the flag under the socket lock in isotp_bind() and taking
the lock in isotp_setsockopt() fixes the issue.
Fixes: 921ca574cd38 ("can: isotp: add SF_BROADCAST support for functional addressing")
Link: https://lore.kernel.org/r/trinity-e6ae9efa-9afb-4326-84c0-f3609b9b8168-1620773528307@3c-app-gmx-bs06
Reported-by: Norbert Slusarek <nslusarek@gmx.net>
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
Signed-off-by: Norbert Slusarek <nslusarek@gmx.net>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
net/can/isotp.c | 49 +++++++++++++++++++++++++++++++++----------------
1 file changed, 33 insertions(+), 16 deletions(-)
diff --git a/net/can/isotp.c b/net/can/isotp.c
index 9f94ad3caee9..253b24417c8e 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -1062,27 +1062,31 @@ static int isotp_bind(struct socket *sock, struct sockaddr *uaddr, int len)
if (len < ISOTP_MIN_NAMELEN)
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 */
if (so->opt.flags & CAN_ISOTP_SF_BROADCAST)
do_rx_reg = 0;
/* do not validate rx address for functional addressing */
if (do_rx_reg) {
- if (addr->can_addr.tp.rx_id == addr->can_addr.tp.tx_id)
- return -EADDRNOTAVAIL;
+ if (addr->can_addr.tp.rx_id == addr->can_addr.tp.tx_id) {
+ err = -EADDRNOTAVAIL;
+ goto out;
+ }
- if (addr->can_addr.tp.rx_id & (CAN_ERR_FLAG | CAN_RTR_FLAG))
- return -EADDRNOTAVAIL;
+ if (addr->can_addr.tp.rx_id & (CAN_ERR_FLAG | CAN_RTR_FLAG)) {
+ 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 &&
addr->can_addr.tp.rx_id == so->rxid &&
addr->can_addr.tp.tx_id == so->txid)
@@ -1164,16 +1168,13 @@ static int isotp_getname(struct socket *sock, struct sockaddr *uaddr, int peer)
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)
{
struct sock *sk = sock->sk;
struct isotp_sock *so = isotp_sk(sk);
int ret = 0;
- if (level != SOL_CAN_ISOTP)
- return -EINVAL;
-
if (so->bound)
return -EISCONN;
@@ -1248,6 +1249,22 @@ static int isotp_setsockopt(struct socket *sock, int level, int optname,
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,
char __user *optval, int __user *optlen)
{
base-commit: 440c3247cba3d9433ac435d371dd7927d68772a7
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: pull-request: can 2021-05-12
2021-05-12 7:10 pull-request: can 2021-05-12 Marc Kleine-Budde
2021-05-12 7:10 ` [net] can: isotp: prevent race between isotp_bind() and isotp_setsockopt() Marc Kleine-Budde
@ 2021-05-12 21:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-05-12 21:20 UTC (permalink / raw)
To: Marc Kleine-Budde; +Cc: netdev, davem, kuba, linux-can, kernel
Hello:
This pull request was applied to netdev/net.git (refs/heads/master):
On Wed, 12 May 2021 09:10:49 +0200 you wrote:
> Hello Jakub, hello David,
>
> 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().
>
> [...]
Here is the summary with links:
- pull-request: can 2021-05-12
https://git.kernel.org/netdev/net/c/364642ae80d6
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-05-12 21:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-12 7:10 pull-request: can 2021-05-12 Marc Kleine-Budde
2021-05-12 7:10 ` [net] can: isotp: prevent race between isotp_bind() and isotp_setsockopt() Marc Kleine-Budde
2021-05-12 21:20 ` pull-request: can 2021-05-12 patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).