diff mbox series

[net,1/2] can: j1939: j1939_sk_setsockopt(): prevent allocation of j1939 filter for optlen == 0

Message ID 20210624064200.2998085-2-mkl@pengutronix.de
State New
Headers show
Series [net,1/2] can: j1939: j1939_sk_setsockopt(): prevent allocation of j1939 filter for optlen == 0 | expand

Commit Message

Marc Kleine-Budde June 24, 2021, 6:41 a.m. UTC
From: Norbert Slusarek <nslusarek@gmx.net>

If optval != NULL and optlen == 0 are specified for SO_J1939_FILTER in
j1939_sk_setsockopt(), memdup_sockptr() will return ZERO_PTR for 0
size allocation. The new filter will be mistakenly assigned ZERO_PTR.
This patch checks for optlen != 0 and filter will be assigned NULL in
case of optlen == 0.

Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol")
Link: https://lore.kernel.org/r/20210620123842.117975-1-nslusarek@gmx.net
Signed-off-by: Norbert Slusarek <nslusarek@gmx.net>
Acked-by: Oleksij Rempel <o.rempel@pengutronix.de>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 net/can/j1939/socket.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


base-commit: c2f5c57d99debf471a1b263cdf227e55f1364e95

Comments

patchwork-bot+netdevbpf@kernel.org June 24, 2021, 6:30 p.m. UTC | #1
Hello:

This series was applied to netdev/net.git (refs/heads/master):

On Thu, 24 Jun 2021 08:41:59 +0200 you wrote:
> From: Norbert Slusarek <nslusarek@gmx.net>
> 
> If optval != NULL and optlen == 0 are specified for SO_J1939_FILTER in
> j1939_sk_setsockopt(), memdup_sockptr() will return ZERO_PTR for 0
> size allocation. The new filter will be mistakenly assigned ZERO_PTR.
> This patch checks for optlen != 0 and filter will be assigned NULL in
> case of optlen == 0.
> 
> [...]

Here is the summary with links:
  - [net,1/2] can: j1939: j1939_sk_setsockopt(): prevent allocation of j1939 filter for optlen == 0
    https://git.kernel.org/netdev/net/c/aaf473d0100f
  - [net,2/2] can: peak_pciefd: pucan_handle_status(): fix a potential starvation issue in TX path
    https://git.kernel.org/netdev/net/c/b17233d385d0

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
diff mbox series

Patch

diff --git a/net/can/j1939/socket.c b/net/can/j1939/socket.c
index fce8bc8afeb7..e1a399821238 100644
--- a/net/can/j1939/socket.c
+++ b/net/can/j1939/socket.c
@@ -676,7 +676,7 @@  static int j1939_sk_setsockopt(struct socket *sock, int level, int optname,
 
 	switch (optname) {
 	case SO_J1939_FILTER:
-		if (!sockptr_is_null(optval)) {
+		if (!sockptr_is_null(optval) && optlen != 0) {
 			struct j1939_filter *f;
 			int c;