Skip to content

Commit

Permalink
af_unix: Do not call kmemdup() for init_net's sysctl table.
Browse files Browse the repository at this point in the history
While setting up init_net's sysctl table, we need not duplicate the global
table and can use it directly.

Fixes: 1597fbc ("[UNIX]: Make the unix sysctl tables per-namespace")
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
  • Loading branch information
q2ven authored and intel-lab-lkp committed Jun 26, 2022
1 parent 3b89b51 commit ba827e6
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions net/unix/sysctl_net_unix.c
Expand Up @@ -26,19 +26,25 @@ int __net_init unix_sysctl_register(struct net *net)
{
struct ctl_table *table;

table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
if (table == NULL)
goto err_alloc;
if (net_eq(net, &init_net)) {
table = unix_table;
} else {
table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
if (!table)
goto err_alloc;

table[0].data = &net->unx.sysctl_max_dgram_qlen;
}

table[0].data = &net->unx.sysctl_max_dgram_qlen;
net->unx.ctl = register_net_sysctl(net, "net/unix", table);
if (net->unx.ctl == NULL)
goto err_reg;

return 0;

err_reg:
kfree(table);
if (net_eq(net, &init_net))
kfree(table);
err_alloc:
return -ENOMEM;
}
Expand Down

0 comments on commit ba827e6

Please sign in to comment.