linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] can: j1939: Remove unnecessary WARN_ON_ONCE in j1939_sk_queue_activate_next_locked()
@ 2022-07-20 11:06 Fedor Pchelkin
  2022-07-20 19:13 ` Oleksij Rempel
  0 siblings, 1 reply; 9+ messages in thread
From: Fedor Pchelkin @ 2022-07-20 11:06 UTC (permalink / raw)
  To: Robin van der Gracht, Oleksij Rempel
  Cc: Fedor Pchelkin, Pengutronix Kernel Team, Oliver Hartkopp,
	Marc Kleine-Budde, David S. Miller, Jakub Kicinski,
	Elenita Hinds, Kurt Van Dijck, linux-can, netdev, linux-kernel,
	Alexey Khoroshilov

The purpose of WARN_ON_ONCE if the session with the same parameters
has already been activated and is currently in active_session_list is
not very clear. Is this warning implemented to indicate that userspace
is doing something wrong?

As far as I can see, there are two lists: active_session_list (which
is for the whole device) and sk_session_queue (which is unique for
each j1939_sock), and the situation when we have two sessions with
the same type, addresses and destinations in two different
sk_session_queues (owned by two different sockets) is actually highly
probable - one is active and the other is willing to become active
but the j1939_session_activate() does not let that happen. It is
correct behaviour as I assume.

Found by Linux Verification Center (linuxtesting.org) with Syzkaller.

Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol")
Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
---
 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 f5ecfdcf57b2..be4b73afa16c 100644
--- a/net/can/j1939/socket.c
+++ b/net/can/j1939/socket.c
@@ -178,7 +178,7 @@ static void j1939_sk_queue_activate_next_locked(struct j1939_session *session)
 	if (!first)
 		return;
 
-	if (WARN_ON_ONCE(j1939_session_activate(first))) {
+	if (j1939_session_activate(first)) {
 		first->err = -EBUSY;
 		goto activate_next;
 	} else {
-- 
2.25.1


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

* Re: [PATCH] can: j1939: Remove unnecessary WARN_ON_ONCE in j1939_sk_queue_activate_next_locked()
  2022-07-20 11:06 [PATCH] can: j1939: Remove unnecessary WARN_ON_ONCE in j1939_sk_queue_activate_next_locked() Fedor Pchelkin
@ 2022-07-20 19:13 ` Oleksij Rempel
  2022-07-28 16:14   ` Fedor Pchelkin
  0 siblings, 1 reply; 9+ messages in thread
From: Oleksij Rempel @ 2022-07-20 19:13 UTC (permalink / raw)
  To: Fedor Pchelkin
  Cc: Robin van der Gracht, Oleksij Rempel, Pengutronix Kernel Team,
	Oliver Hartkopp, Marc Kleine-Budde, David S. Miller,
	Jakub Kicinski, Elenita Hinds, Kurt Van Dijck, linux-can, netdev,
	linux-kernel, Alexey Khoroshilov

Hi Fedor,

On Wed, Jul 20, 2022 at 02:06:45PM +0300, Fedor Pchelkin wrote:
> The purpose of WARN_ON_ONCE if the session with the same parameters
> has already been activated and is currently in active_session_list is
> not very clear. Is this warning implemented to indicate that userspace
> is doing something wrong?

yes.

> As far as I can see, there are two lists: active_session_list (which
> is for the whole device) and sk_session_queue (which is unique for
> each j1939_sock), and the situation when we have two sessions with
> the same type, addresses and destinations in two different
> sk_session_queues (owned by two different sockets) is actually highly
> probable - one is active and the other is willing to become active
> but the j1939_session_activate() does not let that happen. It is
> correct behaviour as I assume.

No. It is not typical use case and most probably it will create
problems. Are you working on some system where this use case is valid?

> Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
> 
> Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol")
> Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
>
> ---
>  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 f5ecfdcf57b2..be4b73afa16c 100644
> --- a/net/can/j1939/socket.c
> +++ b/net/can/j1939/socket.c
> @@ -178,7 +178,7 @@ static void j1939_sk_queue_activate_next_locked(struct j1939_session *session)
>  	if (!first)
>  		return;
>  
> -	if (WARN_ON_ONCE(j1939_session_activate(first))) {
> +	if (j1939_session_activate(first)) {
>  		first->err = -EBUSY;
>  		goto activate_next;
>  	} else {
> -- 
> 2.25.1
> 
> 

-- 
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] 9+ messages in thread

* Re: [PATCH] can: j1939: Remove unnecessary WARN_ON_ONCE in j1939_sk_queue_activate_next_locked()
  2022-07-20 19:13 ` Oleksij Rempel
@ 2022-07-28 16:14   ` Fedor Pchelkin
  2022-07-28 16:34     ` [PATCH] can: j1939: Replace WARN_ON_ONCE with pr_warn_once() " Fedor Pchelkin
  0 siblings, 1 reply; 9+ messages in thread
From: Fedor Pchelkin @ 2022-07-28 16:14 UTC (permalink / raw)
  To: Oleksij Rempel
  Cc: Robin van der Gracht, Oleksij Rempel, Pengutronix Kernel Team,
	Oliver Hartkopp, Marc Kleine-Budde, David S. Miller,
	Jakub Kicinski, Elenita Hinds, Kurt Van Dijck, linux-can, netdev,
	linux-kernel, Alexey Khoroshilov, ldv-project

Hello Oleksij,

I'm sorry for late answering.

On 20.07.2022 22:13, Oleksij Rempel wrote:
>> Are you working on some system where this use case is valid?

No, we are fuzzing the kernel and analyzing different warnings and
crashes.

On 20.07.2022 22:13, Oleksij Rempel wrote:
 > yes

Well, there is a long story about where and for which purposes the
kernel warning macros should be correctly used and, overall,
WARN_ON_ONCE is not intended for user-space notification.

Linus Torvalds wrote:
 > WARN_ON() should only be used for "This cannot happen, but if it does,
 > I want to know how we got here".
 >
 > So if that j1939 thing is something that can be triggered by a user,
 > then the backtrace should be reported to the driver maintainer, and
 > then either
 >
 > (a) the WARN_ON_ONCE() should just be removed ("ok, this can happen,
 > we understand why it can happen, and it's fine")
 >
 > (b) the problem the WARN_ON_ONCE() reports about should be made
 > impossible some way
 >
 > (c) it might be downgraded to a pr_warn() if people really want to
 > tell user space that "guys, you're doing something wrong" and it's
 > considered a useful warning.

So WARN_ON_ONCE should be replaced with a more gentle variant - I think
pr_warn_once would suit this case. I've prepared a new patch for that,
it will follow this email.

Could you also look at the patch - [PATCH] can: j1939: fix memory leak 
of skbs - which I sent you on 08.07.2022, please?

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

* [PATCH] can: j1939: Replace WARN_ON_ONCE with pr_warn_once() in j1939_sk_queue_activate_next_locked()
  2022-07-28 16:14   ` Fedor Pchelkin
@ 2022-07-28 16:34     ` Fedor Pchelkin
  2022-07-28 16:58       ` Oleksij Rempel
  0 siblings, 1 reply; 9+ messages in thread
From: Fedor Pchelkin @ 2022-07-28 16:34 UTC (permalink / raw)
  To: Robin van der Gracht, Oleksij Rempel
  Cc: Fedor Pchelkin, kernel, Oliver Hartkopp, Marc Kleine-Budde,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Kurt Van Dijck, Bastian Stender, linux-can, netdev, linux-kernel,
	Alexey Khoroshilov, ldv-project

We should warn user-space that it is doing something wrong when trying to
activate sessions with identical parameters but WARN_ON_ONCE macro can not
be used here as it serves a different purpose.

Found by Linux Verification Center (linuxtesting.org) with Syzkaller.

Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol")
Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
---
 net/can/j1939/socket.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/can/j1939/socket.c b/net/can/j1939/socket.c
index f5ecfdcf57b2..67e8b50b8bc1 100644
--- a/net/can/j1939/socket.c
+++ b/net/can/j1939/socket.c
@@ -178,7 +178,8 @@ static void j1939_sk_queue_activate_next_locked(struct j1939_session *session)
 	if (!first)
 		return;
 
-	if (WARN_ON_ONCE(j1939_session_activate(first))) {
+	if (j1939_session_activate(first)) {
+		pr_warn_once("can: j1939: Identical session is already activated.\n");
 		first->err = -EBUSY;
 		goto activate_next;
 	} else {
-- 
2.25.1


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

* Re: [PATCH] can: j1939: Replace WARN_ON_ONCE with pr_warn_once() in j1939_sk_queue_activate_next_locked()
  2022-07-28 16:34     ` [PATCH] can: j1939: Replace WARN_ON_ONCE with pr_warn_once() " Fedor Pchelkin
@ 2022-07-28 16:58       ` Oleksij Rempel
  2022-07-29 14:06         ` [PATCH v2] can: j1939: Replace WARN_ON_ONCE with netdev_warn_once() " Fedor Pchelkin
  0 siblings, 1 reply; 9+ messages in thread
From: Oleksij Rempel @ 2022-07-28 16:58 UTC (permalink / raw)
  To: Fedor Pchelkin
  Cc: Robin van der Gracht, Oleksij Rempel, kernel, Oliver Hartkopp,
	Marc Kleine-Budde, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Kurt Van Dijck, Bastian Stender, linux-can, netdev,
	linux-kernel, Alexey Khoroshilov, ldv-project

Hi Fedor,

thank you for your patch.

On Thu, Jul 28, 2022 at 07:34:29PM +0300, Fedor Pchelkin wrote:
> We should warn user-space that it is doing something wrong when trying to
> activate sessions with identical parameters but WARN_ON_ONCE macro can not
> be used here as it serves a different purpose.
> 
> Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
> 
> Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol")
> Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
> ---
>  net/can/j1939/socket.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/net/can/j1939/socket.c b/net/can/j1939/socket.c
> index f5ecfdcf57b2..67e8b50b8bc1 100644
> --- a/net/can/j1939/socket.c
> +++ b/net/can/j1939/socket.c
> @@ -178,7 +178,8 @@ static void j1939_sk_queue_activate_next_locked(struct j1939_session *session)
>  	if (!first)
>  		return;
>  
> -	if (WARN_ON_ONCE(j1939_session_activate(first))) {
> +	if (j1939_session_activate(first)) {
> +		pr_warn_once("can: j1939: Identical session is already activated.\n");

please use netdev_warn_once().
Otherwise looks good.

>  		first->err = -EBUSY;
>  		goto activate_next;
>  	} else {
> -- 
> 2.25.1
> 
> 

-- 
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] 9+ messages in thread

* [PATCH v2] can: j1939: Replace WARN_ON_ONCE with netdev_warn_once() in j1939_sk_queue_activate_next_locked()
  2022-07-28 16:58       ` Oleksij Rempel
@ 2022-07-29 14:06         ` Fedor Pchelkin
  2022-07-29 14:26           ` Oleksij Rempel
  0 siblings, 1 reply; 9+ messages in thread
From: Fedor Pchelkin @ 2022-07-29 14:06 UTC (permalink / raw)
  To: Robin van der Gracht, Oleksij Rempel
  Cc: Fedor Pchelkin, kernel, Oliver Hartkopp, Marc Kleine-Budde,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	linux-can, netdev, linux-kernel, Alexey Khoroshilov, ldv-project

We should warn user-space that it is doing something wrong when trying to
activate sessions with identical parameters but WARN_ON_ONCE macro can not
be used here as it serves a different purpose.

So it would be good to replace it with netdev_warn_once() message.

Found by Linux Verification Center (linuxtesting.org) with Syzkaller.

Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol")
Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
---
v1 -> v2: Used netdev_warn_once() instead of pr_warn_once()

 net/can/j1939/socket.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/can/j1939/socket.c b/net/can/j1939/socket.c
index f5ecfdcf57b2..09e1d78bd22c 100644
--- a/net/can/j1939/socket.c
+++ b/net/can/j1939/socket.c
@@ -178,7 +178,10 @@ static void j1939_sk_queue_activate_next_locked(struct j1939_session *session)
 	if (!first)
 		return;
 
-	if (WARN_ON_ONCE(j1939_session_activate(first))) {
+	if (j1939_session_activate(first)) {
+		netdev_warn_once(first->priv->ndev,
+						 "%s: 0x%p: Identical session is already activated.\n",
+						 __func__, first);
 		first->err = -EBUSY;
 		goto activate_next;
 	} else {
-- 
2.25.1


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

* Re: [PATCH v2] can: j1939: Replace WARN_ON_ONCE with netdev_warn_once() in j1939_sk_queue_activate_next_locked()
  2022-07-29 14:06         ` [PATCH v2] can: j1939: Replace WARN_ON_ONCE with netdev_warn_once() " Fedor Pchelkin
@ 2022-07-29 14:26           ` Oleksij Rempel
  2022-07-29 14:36             ` Fedor Pchelkin
  0 siblings, 1 reply; 9+ messages in thread
From: Oleksij Rempel @ 2022-07-29 14:26 UTC (permalink / raw)
  To: Fedor Pchelkin
  Cc: Robin van der Gracht, Oleksij Rempel, kernel, Oliver Hartkopp,
	Marc Kleine-Budde, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, linux-can, netdev, linux-kernel, Alexey Khoroshilov,
	ldv-project

On Fri, Jul 29, 2022 at 05:06:09PM +0300, Fedor Pchelkin wrote:
> We should warn user-space that it is doing something wrong when trying to
> activate sessions with identical parameters but WARN_ON_ONCE macro can not
> be used here as it serves a different purpose.
> 
> So it would be good to replace it with netdev_warn_once() message.
> 
> Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
> 
> Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol")
> Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>

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

> ---
> v1 -> v2: Used netdev_warn_once() instead of pr_warn_once()
> 
>  net/can/j1939/socket.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/net/can/j1939/socket.c b/net/can/j1939/socket.c
> index f5ecfdcf57b2..09e1d78bd22c 100644
> --- a/net/can/j1939/socket.c
> +++ b/net/can/j1939/socket.c
> @@ -178,7 +178,10 @@ static void j1939_sk_queue_activate_next_locked(struct j1939_session *session)
>  	if (!first)
>  		return;
>  
> -	if (WARN_ON_ONCE(j1939_session_activate(first))) {
> +	if (j1939_session_activate(first)) {
> +		netdev_warn_once(first->priv->ndev,
> +						 "%s: 0x%p: Identical session is already activated.\n",
> +						 __func__, first);
>  		first->err = -EBUSY;
>  		goto activate_next;
>  	} else {
> -- 
> 2.25.1
> 
> 

-- 
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] 9+ messages in thread

* [PATCH v2] can: j1939: Replace WARN_ON_ONCE with netdev_warn_once() in j1939_sk_queue_activate_next_locked()
  2022-07-29 14:26           ` Oleksij Rempel
@ 2022-07-29 14:36             ` Fedor Pchelkin
  2022-08-08  8:06               ` Marc Kleine-Budde
  0 siblings, 1 reply; 9+ messages in thread
From: Fedor Pchelkin @ 2022-07-29 14:36 UTC (permalink / raw)
  To: Robin van der Gracht, Oleksij Rempel
  Cc: Fedor Pchelkin, kernel, Oliver Hartkopp, Marc Kleine-Budde,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	linux-can, netdev, linux-kernel, Alexey Khoroshilov, ldv-project,
	Oleksij Rempel

We should warn user-space that it is doing something wrong when trying to
activate sessions with identical parameters but WARN_ON_ONCE macro can not
be used here as it serves a different purpose.

So it would be good to replace it with netdev_warn_once() message.

Found by Linux Verification Center (linuxtesting.org) with Syzkaller.

Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol")
Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
Acked-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
v1 -> v2: Used netdev_warn_once() instead of pr_warn_once()

 net/can/j1939/socket.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/can/j1939/socket.c b/net/can/j1939/socket.c
index f5ecfdcf57b2..09e1d78bd22c 100644
--- a/net/can/j1939/socket.c
+++ b/net/can/j1939/socket.c
@@ -178,7 +178,10 @@ static void j1939_sk_queue_activate_next_locked(struct j1939_session *session)
 	if (!first)
 		return;
 
-	if (WARN_ON_ONCE(j1939_session_activate(first))) {
+	if (j1939_session_activate(first)) {
+		netdev_warn_once(first->priv->ndev,
+						 "%s: 0x%p: Identical session is already activated.\n",
+						 __func__, first);
 		first->err = -EBUSY;
 		goto activate_next;
 	} else {
-- 
2.25.1


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

* Re: [PATCH v2] can: j1939: Replace WARN_ON_ONCE with netdev_warn_once() in j1939_sk_queue_activate_next_locked()
  2022-07-29 14:36             ` Fedor Pchelkin
@ 2022-08-08  8:06               ` Marc Kleine-Budde
  0 siblings, 0 replies; 9+ messages in thread
From: Marc Kleine-Budde @ 2022-08-08  8:06 UTC (permalink / raw)
  To: Fedor Pchelkin
  Cc: Robin van der Gracht, Oleksij Rempel, kernel, Oliver Hartkopp,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	linux-can, netdev, linux-kernel, Alexey Khoroshilov, ldv-project,
	Oleksij Rempel

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

On 29.07.2022 17:36:55, Fedor Pchelkin wrote:
> We should warn user-space that it is doing something wrong when trying to
> activate sessions with identical parameters but WARN_ON_ONCE macro can not
> be used here as it serves a different purpose.
> 
> So it would be good to replace it with netdev_warn_once() message.
> 
> Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
> 
> Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol")
> Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
> Acked-by: Oleksij Rempel <o.rempel@pengutronix.de>

Nitpick: You should add your S-o-b below every other tag line.

Added to linux-can with fixed indention.

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] 9+ messages in thread

end of thread, other threads:[~2022-08-08  8:07 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-20 11:06 [PATCH] can: j1939: Remove unnecessary WARN_ON_ONCE in j1939_sk_queue_activate_next_locked() Fedor Pchelkin
2022-07-20 19:13 ` Oleksij Rempel
2022-07-28 16:14   ` Fedor Pchelkin
2022-07-28 16:34     ` [PATCH] can: j1939: Replace WARN_ON_ONCE with pr_warn_once() " Fedor Pchelkin
2022-07-28 16:58       ` Oleksij Rempel
2022-07-29 14:06         ` [PATCH v2] can: j1939: Replace WARN_ON_ONCE with netdev_warn_once() " Fedor Pchelkin
2022-07-29 14:26           ` Oleksij Rempel
2022-07-29 14:36             ` Fedor Pchelkin
2022-08-08  8:06               ` 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).