diff mbox series

[net] netrom: fix sleep in atomic context bugs in timer handlers

Message ID 20220723035646.29857-1-duoming@zju.edu.cn (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net] netrom: fix sleep in atomic context bugs in timer handlers | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers fail 1 blamed authors not CCed: acme@mandriva.com; 1 maintainers not CCed: acme@mandriva.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Duoming Zhou July 23, 2022, 3:56 a.m. UTC
There are sleep in atomic context bugs in timer handlers of netrom
such as nr_t1timer_expiry(), nr_t2timer_expiry(), nr_heartbeat_expiry(),
nr_idletimer_expiry() and so on.

The root cause is kmemdup() with GFP_KERNEL parameter that may sleep
could be called by different timer handlers which is in interrupt context.

One of the call paths that could trigger bug is shown below:

      (interrupt context)
nr_heartbeat_expiry
  nr_write_internal
    nr_transmit_buffer
      nr_route_frame
        nr_add_node
          kmemdup(..,GFP_KERNEL) //may sleep

This patch changes gfp_t parameter of kmemdup in nr_add_node()
from GFP_KERNEL to GFP_ATOMIC in order to prevent sleep in atomic
context bugs.

Fixes: eafff86d3bd8 ("[NETROM]: Use kmemdup")
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
---
 net/netrom/nr_route.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jakub Kicinski July 26, 2022, 2:49 a.m. UTC | #1
On Sat, 23 Jul 2022 11:56:46 +0800 Duoming Zhou wrote:
> Fixes: eafff86d3bd8 ("[NETROM]: Use kmemdup")

That's not a correct Fixes tag, acme just swapped kmalloc for kmemdup().
The allocate flags did not change.
Duoming Zhou July 26, 2022, 3:20 a.m. UTC | #2
Hello,

On Mon, 25 Jul 2022 19:49:30 -0700 Jakub Kicinski wrote:

> On Sat, 23 Jul 2022 11:56:46 +0800 Duoming Zhou wrote:
> > Fixes: eafff86d3bd8 ("[NETROM]: Use kmemdup")
> 
> That's not a correct Fixes tag, acme just swapped kmalloc for kmemdup().
> The allocate flags did not change.

Thanks for your time and reply!

The correct Fixes tag is "Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")".
The following is the code:

https://elixir.bootlin.com/linux/v2.6.12-rc2/source/net/netrom/nr_route.c#L158

...
if ((nr_neigh->digipeat = kmalloc(sizeof(*ax25_digi), GFP_KERNEL)) == NULL) {
...

Best regards,
Duoming Zhou
diff mbox series

Patch

diff --git a/net/netrom/nr_route.c b/net/netrom/nr_route.c
index baea3cbd76c..1ddcf13de6a 100644
--- a/net/netrom/nr_route.c
+++ b/net/netrom/nr_route.c
@@ -163,7 +163,7 @@  static int __must_check nr_add_node(ax25_address *nr, const char *mnemonic,
 		if (ax25_digi != NULL && ax25_digi->ndigi > 0) {
 			nr_neigh->digipeat = kmemdup(ax25_digi,
 						     sizeof(*ax25_digi),
-						     GFP_KERNEL);
+						     GFP_ATOMIC);
 			if (nr_neigh->digipeat == NULL) {
 				kfree(nr_neigh);
 				if (nr_node)