netfilter: snmp: Fix one possible panic when snmp_trap_helper fail to register
Subsystems (2)
PATCH v4 1/1 netfilter: snmp: Fix one possible panic when snmp_trap_helper fail to register
From: Gao Feng <[email protected]>
In the commit 93557f53e1fb ("netfilter: nf_conntrack: nf_conntrack snmp helper"), the snmp_helper is replaced by nf_nat_snmp_hook. So the snmp_helper is never registered. But it still tries to unregister the snmp_helper, it could cause the panic.
Now remove the useless snmp_helper and the unregister call in the error handler.
---
v4: Simplify the codes, per Pablo
v3: Remove the angle brackets in description, per Sergei
v2: Add the SHA1 ID in the description, per Sergei
v1: Initial version
net/ipv4/netfilter/nf_nat_snmp_basic.c | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-)
net/ipv4/netfilter/nf_nat_snmp_basic.c +1 -16
@@ -1260,16 +1260,6 @@ static int help(struct sk_buff *skb, unsigned int protoff, .timeout = 180, }; -static struct nf_conntrack_helper snmp_helper__read_mostly = { - .me =THIS_MODULE , - .help = help, - .expect_policy = &snmp_exp_policy, - .name ="snmp" , - .tuple.src.l3num =AF_INET , - .tuple.src.u.udp.port =cpu_to_be16 (SNMP_PORT ), - .tuple.dst.protonum =IPPROTO_UDP , -}; -static struct nf_conntrack_helper snmp_trap_helper__read_mostly = { .me =THIS_MODULE , .help = help,
@@ -1293,12 +1283,7 @@ static int __init nf_nat_snmp_basic_init(void)BUG_ON (nf_nat_snmp_hook !=NULL );RCU_INIT_POINTER (nf_nat_snmp_hook, help); - ret =nf_conntrack_helper_register (&snmp_trap_helper); -if (ret <0 ) { -nf_conntrack_helper_unregister (&snmp_helper); -return ret; - } -return ret; +return nf_conntrack_helper_register (&snmp_trap_helper); } static void __exit nf_nat_snmp_basic_fini(void)
Signature · 1 line
1.9.1
Hi Feng,
2017-03-25 10:24 GMT+08:00 <[email protected]>:
[...]
net/ipv4/netfilter/nf_nat_snmp_basic.c static int __init nf_nat_snmp_basic_init(void) · line 1286
Quoted 11 lines
net/ipv4/netfilter/nf_nat_snmp_basic.c +1
-6@@ -1293,12 +1283,7 @@ static int __init nf_nat_snmp_basic_init(void)BUG_ON (nf_nat_snmp_hook !=NULL );RCU_INIT_POINTER (nf_nat_snmp_hook, help); - ret =nf_conntrack_helper_register (&snmp_trap_helper); -if (ret <0 ) { -nf_conntrack_helper_unregister (&snmp_helper); -return ret; - } -return ret; +return nf_conntrack_helper_register (&snmp_trap_helper);
I think you should also remove the "int ret = 0;" statement,
static int __init nf_nat_snmp_basic_init(void)
{
int ret = 0; <--- HereOtherwise, GCC will warn "unused variable".
Hi Liping,
Quoted 27 lines
-----Original Message-----
From: Liping Zhang [mailto:[email protected]]
Sent: Saturday, March 25, 2017 4:17 PM
To: [email protected]
Cc: Pablo Neira Ayuso <[email protected]>; Netfilter Developer Mailing List <[email protected]>; Gao Feng <[email protected]>
Subject: Re: [PATCH nf v4 1/1] netfilter: snmp: Fix one possible panic whensnmp_trap_helperfail to registerHi Feng,
2017-03-25 10:24 GMT+08:00 <[email protected]>:
[...]net/ipv4/netfilter/nf_nat_snmp_basic.c static int __init nf_nat_snmp_basic_init(void) · line 1286
Quoted 11 lines
net/ipv4/netfilter/nf_nat_snmp_basic.c +1
-6@@ -1293,12 +1283,7 @@ static int __init nf_nat_snmp_basic_init(void)BUG_ON (nf_nat_snmp_hook !=NULL );RCU_INIT_POINTER (nf_nat_snmp_hook, help); - ret =nf_conntrack_helper_register (&snmp_trap_helper); -if (ret <0 ) { -nf_conntrack_helper_unregister (&snmp_helper); -return ret; - } -return ret; +return nf_conntrack_helper_register (&snmp_trap_helper);I think you should also remove the "int ret = 0;" statement,
Quoted 4 lines
static int __init nf_nat_snmp_basic_init(void) { int ret = 0; <--- HereOtherwise, GCC will warn "unused variable".
Thanks.
I didn't see the warning during compiling.
I think it should be overlapped because I pull the upstream. There are other changes.
Next time, I would only touch the changed files and compile. Thanks again.
Feng
kbuild test robot
build botreproduce:
Hi Gao,
[auto build test WARNING on nf/master]
url: https://github.com/0day-ci/linux/commits/gfree-wind-foxmail-com/netfilter-snmp-Fix-one-possible-panic-when-snmp_trap_helper-fail-to-register/20170327-081220 base: https://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git master config: x86_64-randconfig-s2-03272042 (attached as .config) compiler: gcc-4.4 (Debian 4.4.7-8) 4.4.7 reproduce: # save the attached .config to linux build tree make ARCH=x86_64
All warnings (new ones prefixed by >>):
net/ipv4//netfilter/nf_nat_snmp_basic.c: In function 'nf_nat_snmp_basic_init':
>> net/ipv4//netfilter/nf_nat_snmp_basic.c:1281: warning: unused variable 'ret'
vim +/ret +1281 net/ipv4//netfilter/nf_nat_snmp_basic.c
807467c22 Patrick McHardy 2006-12-02 1265 .help = help,
6002f266b Patrick McHardy 2008-03-25 1266 .expect_policy = &snmp_exp_policy,
807467c22 Patrick McHardy 2006-12-02 1267 .name = "snmp_trap",
807467c22 Patrick McHardy 2006-12-02 1268 .tuple.src.l3num = AF_INET,
09640e636 Harvey Harrison 2009-02-01 1269 .tuple.src.u.udp.port = cpu_to_be16(SNMP_TRAP_PORT),
807467c22 Patrick McHardy 2006-12-02 1270 .tuple.dst.protonum = IPPROTO_UDP,
807467c22 Patrick McHardy 2006-12-02 1271 };
807467c22 Patrick McHardy 2006-12-02 1272
807467c22 Patrick McHardy 2006-12-02 1273 /*****************************************************************************
807467c22 Patrick McHardy 2006-12-02 1274 *
807467c22 Patrick McHardy 2006-12-02 1275 * Module stuff.
807467c22 Patrick McHardy 2006-12-02 1276 *
807467c22 Patrick McHardy 2006-12-02 1277 *****************************************************************************/
807467c22 Patrick McHardy 2006-12-02 1278
807467c22 Patrick McHardy 2006-12-02 1279 static int __init nf_nat_snmp_basic_init(void)
807467c22 Patrick McHardy 2006-12-02 1280 {
807467c22 Patrick McHardy 2006-12-02 @1281 int ret = 0;
807467c22 Patrick McHardy 2006-12-02 1282
93557f53e Jiri Olsa 2011-01-18 1283 BUG_ON(nf_nat_snmp_hook != NULL);
a9b3cd7f3 Stephen Hemminger 2011-08-01 1284 RCU_INIT_POINTER(nf_nat_snmp_hook, help);
93557f53e Jiri Olsa 2011-01-18 1285
9b25a2987 Gao Feng 2017-03-25 1286 return nf_conntrack_helper_register(&snmp_trap_helper);
807467c22 Patrick McHardy 2006-12-02 1287 }
807467c22 Patrick McHardy 2006-12-02 1288
807467c22 Patrick McHardy 2006-12-02 1289 static void __exit nf_nat_snmp_basic_fini(void):::::: The code at line 1281 was first introduced by commit
:::::: 807467c22a12381985878be23c778657fc0364d0 [NETFILTER]: nf_nat: add SNMP NAT helper port
:::::: TO: Patrick McHardy <[email protected]>
:::::: CC: David S. Miller <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Quoted 4 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of kbuild test
robot
Quoted 3 lines
Sent: Monday, March 27, 2017 10:01 PM
To: [email protected]
Cc: [email protected]; [email protected];
Quoted 2 lines
[email protected]; Gao Feng <[email protected]>
Subject: Re: [PATCH nf v4 1/1] netfilter: snmp: Fix one possible panic
when
Quoted 8 lines
snmp_trap_helperfail to registerHi Gao,
[auto build test WARNING on nf/master]
url:
https://github.com/0day-ci/linux/commits/gfree-wind-foxmail-com/netfilter-s
Quoted 3 lines
nmp-Fix-one-possible-panic-when-snmp_trap_helper-fail-to-register/2017032 7-081220
base: https://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
master
Quoted 8 lines
config: x86_64-randconfig-s2-03272042 (attached as .config)
compiler: gcc-4.4 (Debian 4.4.7-8) 4.4.7 reproduce:# save the attached .config to linux build tree make ARCH=x86_64All warnings (new ones prefixed by >>):
Quoted 8 lines
net/ipv4//netfilter/nf_nat_snmp_basic.c: In function
'nf_nat_snmp_basic_init':Quoted 1 line
Quoted 1 line
net/ipv4//netfilter/nf_nat_snmp_basic.c:1281: warning: unused variable
'ret'
vim +/ret +1281 net/ipv4//netfilter/nf_nat_snmp_basic.c
807467c22Patrick McHardy 2006-12-02 1265 .help
=
Quoted 2 lines
help,
6002f266bPatrick McHardy 2008-03-25 1266 .expect_policy
=
Quoted 2 lines
&snmp_exp_policy,807467c22Patrick McHardy 2006-12-02 1267 .name
=
Quoted 2 lines
"
snmp_trap",807467c22Patrick McHardy 2006-12-02 1268 .tuple.src.l3num
=
Quoted 2 lines
AF_INET,09640e636Harvey Harrison 2009-02-01 1269
.tuple.src.u.udp.port =
Quoted 2 lines
cpu_to_be16(SNMP_TRAP_PORT),807467c22Patrick McHardy 2006-12-02 1270 .tuple.dst.protonum
=
Quoted 34 lines
IPPROTO_UDP,807467c22 Patrick McHardy 2006-12-02 1271 }; 807467c22 Patrick McHardy 2006-12-02 1272 807467c22 Patrick McHardy 2006-12-02 1273 /*************************************************************** ************** 807467c22 Patrick McHardy 2006-12-02 1274 * 807467c22 Patrick McHardy 2006-12-02 1275 * Module stuff. 807467c22 Patrick McHardy 2006-12-02 1276 * 807467c22 Patrick McHardy 2006-12-02 1277 **************************************************************** *************/ 807467c22 Patrick McHardy 2006-12-02 1278 807467c22 Patrick McHardy 2006-12-02 1279 static int __init nf_nat_snmp_basic_init(void) 807467c22 Patrick McHardy 2006-12-02 1280 { 807467c22 Patrick McHardy 2006-12-02 @1281 int ret = 0; 807467c22 Patrick McHardy 2006-12-02 1282 93557f53e Jiri Olsa 2011-01-18 1283 BUG_ON(nf_nat_snmp_hook != NULL); a9b3cd7f3 Stephen Hemminger 2011-08-01 1284 RCU_INIT_POINTER(nf_nat_snmp_hook, help); 93557f53e Jiri Olsa 2011-01-18 1285 9b25a2987 Gao Feng 2017-03-25 1286 return nf_conntrack_helper_register(&snmp_trap_helper); 807467c22 Patrick McHardy 2006-12-02 1287 } 807467c22 Patrick McHardy 2006-12-02 1288 807467c22 Patrick McHardy 2006-12-02 1289 static void __exit
nf_nat_snmp_basic_fini(void):::::: The code at line 1281 was first introduced by commit ::::::
807467c22a12381985878be23c778657fc0364d0[NETFILTER]:nf_nat: add SNMP NAT helper port
Quoted 8 lines
:::::: TO: Patrick McHardy <[email protected]>
:::::: CC: David S. Miller <[email protected]>---
0-DAY kernel test infrastructure Open Source Technology
Center
https://lists.01.org/pipermail/kbuild-all Intel
Corporation
Thanks.
It is fixed in v5 patch.
Regards
Feng