netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] can: j1939: prevent allocation of j1939 filter for optlen = 0
@ 2021-06-20 12:38 Norbert Slusarek
  2021-06-21  4:47 ` Oleksij Rempel
  2021-06-21  7:47 ` Marc Kleine-Budde
  0 siblings, 2 replies; 3+ messages in thread
From: Norbert Slusarek @ 2021-06-20 12:38 UTC (permalink / raw)
  To: netdev; +Cc: ore, mkl, socketcan, davem, kuba, linux-can, nslusarek, kernel

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: a7b75c5a8c41 ("net: pass a sockptr_t into ->setsockopt")
Signed-off-by: Norbert Slusarek <nslusarek@gmx.net>

---
 net/can/j1939/socket.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/can/j1939/socket.c b/net/can/j1939/socket.c
index 56aa66147d5a..ff20cb629200 100644
--- a/net/can/j1939/socket.c
+++ b/net/can/j1939/socket.c
@@ -673,7 +673,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;

--
2.30.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] can: j1939: prevent allocation of j1939 filter for optlen = 0
  2021-06-20 12:38 [PATCH] can: j1939: prevent allocation of j1939 filter for optlen = 0 Norbert Slusarek
@ 2021-06-21  4:47 ` Oleksij Rempel
  2021-06-21  7:47 ` Marc Kleine-Budde
  1 sibling, 0 replies; 3+ messages in thread
From: Oleksij Rempel @ 2021-06-21  4:47 UTC (permalink / raw)
  To: Norbert Slusarek; +Cc: netdev, socketcan, linux-can, mkl, kernel, kuba, davem

Hi Norbert,

On Sun, Jun 20, 2021 at 02:38:42PM +0200, Norbert Slusarek wrote:
> 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: a7b75c5a8c41 ("net: pass a sockptr_t into ->setsockopt")
> Signed-off-by: Norbert Slusarek <nslusarek@gmx.net>

Acked-by: Oleksij Rempel <o.rempel@pengutronix.de>

Thank you!

> ---
>  net/can/j1939/socket.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/can/j1939/socket.c b/net/can/j1939/socket.c
> index 56aa66147d5a..ff20cb629200 100644
> --- a/net/can/j1939/socket.c
> +++ b/net/can/j1939/socket.c
> @@ -673,7 +673,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;
> 
> --
> 2.30.2
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] can: j1939: prevent allocation of j1939 filter for optlen = 0
  2021-06-20 12:38 [PATCH] can: j1939: prevent allocation of j1939 filter for optlen = 0 Norbert Slusarek
  2021-06-21  4:47 ` Oleksij Rempel
@ 2021-06-21  7:47 ` Marc Kleine-Budde
  1 sibling, 0 replies; 3+ messages in thread
From: Marc Kleine-Budde @ 2021-06-21  7:47 UTC (permalink / raw)
  To: Norbert Slusarek; +Cc: netdev, ore, socketcan, davem, kuba, linux-can, kernel

[-- Attachment #1: Type: text/plain, Size: 959 bytes --]

On 20.06.2021 14:38:42, Norbert Slusarek wrote:
> 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: a7b75c5a8c41 ("net: pass a sockptr_t into ->setsockopt")
> Signed-off-by: Norbert Slusarek <nslusarek@gmx.net>

The problem was in the initial commit, too. Changed Fixes tags
accordingly to:

| Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol")

applied to linux-can/testing

regards,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-06-21  7:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-20 12:38 [PATCH] can: j1939: prevent allocation of j1939 filter for optlen = 0 Norbert Slusarek
2021-06-21  4:47 ` Oleksij Rempel
2021-06-21  7:47 ` Marc Kleine-Budde

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).