[Openswan dev] [PATCH][2.6.41] Kernel warnings and empty /proc/net/ on module unload (kernel < 3.9.0)

Tijs Van Buggenhout tijs.van.buggenhout at able.be
Fri Mar 7 12:28:52 EST 2014


I'm using latest openswan release (2.6.41) to build the KLIPS module for (long 
stable) kernel version 3.2(.55) and got some strange kernel WARNINGS when
unloading the ipsec module. As a consequence after unloading the module the
entire /proc/net/ contents is wiped clean. This is already reported on github
aswell [1].

Relevant kernel warnings: 

klips_info:pfkey_cleanup: shutting down PF_KEY domain sockets.
NET: Unregistered protocol family 15
------------[ cut here ]------------
WARNING: at /ub/src/linux-3.2-axs-1/fs/proc/generic.c:808 
remove_proc_entry+0x193/0x1f0()
Hardware name: PDSMi
name 'pf_key'
Modules linked in: nfnetlink_log xt_condition(O) xt_NFQUEUE appletalk ipx 
p8022 psnap llc p8023 tun cast6 deflate ctr gcm ccm ecb xcbc md5 
sha256_generic sha512_generic des_generic blowfish_generic blowfish_common 
cast5 serpent twofish_generic twofish_i586 twofish_common aes_i586 aes_generic 
cbc ipsec(O-) ip_gre netconsole configfs xt_comment ipt_REDIRECT 
ipt_MASQUERADE ipip tunnel4 pppoatm xt_TCPMSS xt_connmark nf_nat_proto_sctp 
nf_nat_proto_udplite nf_nat_pptp nf_nat_proto_gre nf_nat_h323 nf_nat_irc 
nf_nat_proto_dccp nf_nat_ftp ts_kmp nf_conntrack_proto_dccp 
nf_conntrack_proto_sctp nf_conntrack_pptp nf_conntrack_irc 
nf_conntrack_netlink nf_conntrack_h323 nf_conntrack_ftp 
nf_conntrack_netbios_ns nf_conntrack_sane nf_conntrack_proto_udplite 
nf_conntrack_snmp nf_conntrack_proto_gre nf_conntrack_broadcast ipt_REJECT 
ipt_LOG xt_limit xt_tcpudp xt_state xt_mark nfnetlink_queue nfnetlink 
ip6table_filter ip6_tables iptable_mangle iptable_nat nf_nat nf_conntrack_ipv4 
nf_defrag_ipv4 iptable_filter ip_tables x_tables nf_conntrack ppp_deflate 
zlib_deflate bsd_comp ppp_generic slhc unicorn_pci_atm(P) atm e1000 e1000e(O) 
8139too mii ftdi_sio usbserial dm_mod usbhid uhci_hcd ohci_hcd ehci_hcd 
usbcore usb_common [last unloaded: pl2303]
Pid: 3558, comm: rmmod Tainted: P           O 3.2-axs-1 #1
Call Trace:
 [<c1031ead>] warn_slowpath_common+0x6d/0xa0
 [<c10f5bc3>] ? remove_proc_entry+0x193/0x1f0
 [<c10f5bc3>] ? remove_proc_entry+0x193/0x1f0
 [<c1031f5e>] warn_slowpath_fmt+0x2e/0x30
 [<c10f5bc3>] remove_proc_entry+0x193/0x1f0
 [<f974a046>] ? backport_proc_subdir_remove+0x26/0x30 [ipsec]
 [<f974a144>] remove_proc_subtree+0x44/0x50 [ipsec]
 [<f974b7e0>] pfkey_cleanup+0x60/0x90 [ipsec]
 [<f97362ec>] cleanup_module+0xcc/0x190 [ipsec]
 [<c105e342>] ? module_refcount+0x72/0x90
 [<c105f577>] sys_delete_module+0x107/0x250
 [<c1090063>] ? vma_adjust+0x343/0x4d0
 [<c1321f75>] syscall_call+0x7/0xb
---[ end trace 6cba7fefe6575269 ]---
------------[ cut here ]------------
WARNING: at /ub/src/linux-3.2-axs-1/fs/proc/generic.c:808 
remove_proc_entry+0x193/0x1f0()
Hardware name: PDSMi
name 'pf_key_supported'
Modules linked in: nfnetlink_log xt_condition(O) xt_NFQUEUE appletalk ipx 
p8022 psnap llc p8023 tun cast6 deflate ctr gcm ccm ecb xcbc md5 
sha256_generic sha512_generic des_generic blowfish_generic blowfish_common 
cast5 serpent twofish_generic twofish_i586 twofish_common aes_i586 aes_generic 
cbc ipsec(O-) ip_gre netconsole configfs xt_comment ipt_REDIRECT 
ipt_MASQUERADE ipip tunnel4 pppoatm xt_TCPMSS xt_connmark nf_nat_proto_sctp 
nf_nat_proto_udplite nf_nat_pptp nf_nat_proto_gre nf_nat_h323 nf_nat_irc 
nf_nat_proto_dccp nf_nat_ftp ts_kmp nf_conntrack_proto_dccp 
nf_conntrack_proto_sctp nf_conntrack_pptp nf_conntrack_irc 
nf_conntrack_netlink nf_conntrack_h323 nf_conntrack_ftp 
nf_conntrack_netbios_ns nf_conntrack_sane nf_conntrack_proto_udplite 
nf_conntrack_snmp nf_conntrack_proto_gre nf_conntrack_broadcast ipt_REJECT 
ipt_LOG xt_limit xt_tcpudp xt_state xt_mark nfnetlink_queue nfnetlink 
ip6table_filter ip6_tables iptable_mangle iptable_nat nf_nat nf_conntrack_ipv4 
nf_defrag_ipv4 iptable_filter ip_tables x_tables nf_conntrack ppp_deflate 
zlib_deflate bsd_comp ppp_generic slhc unicorn_pci_atm(P) atm e1000 e1000e(O) 
8139too mii ftdi_sio usbserial dm_mod usbhid uhci_hcd ohci_hcd ehci_hcd 
usbcore usb_common [last unloaded: pl2303]
Pid: 3558, comm: rmmod Tainted: P        W  O 3.2-axs-1 #1
Call Trace:
 [<c1031ead>] warn_slowpath_common+0x6d/0xa0
 [<c10f5bc3>] ? remove_proc_entry+0x193/0x1f0
 [<c10f5bc3>] ? remove_proc_entry+0x193/0x1f0
 [<c1031f5e>] warn_slowpath_fmt+0x2e/0x30
 [<c10f5bc3>] remove_proc_entry+0x193/0x1f0
 [<f974a046>] ? backport_proc_subdir_remove+0x26/0x30 [ipsec]
 [<f974a144>] remove_proc_subtree+0x44/0x50 [ipsec]
 [<f974b7f0>] pfkey_cleanup+0x70/0x90 [ipsec]
 [<f97362ec>] cleanup_module+0xcc/0x190 [ipsec]
 [<c105e342>] ? module_refcount+0x72/0x90
 [<c105f577>] sys_delete_module+0x107/0x250
 [<c1090063>] ? vma_adjust+0x343/0x4d0
 [<c1321f75>] syscall_call+0x7/0xb
---[ end trace 6cba7fefe657526a ]---
------------[ cut here ]------------
WARNING: at /ub/src/linux-3.2-axs-1/fs/proc/generic.c:808 
remove_proc_entry+0x193/0x1f0()
Hardware name: PDSMi
name 'pf_key_registered'
Modules linked in: nfnetlink_log xt_condition(O) xt_NFQUEUE appletalk ipx 
p8022 psnap llc p8023 tun cast6 deflate ctr gcm ccm ecb xcbc md5 
sha256_generic sha512_generic des_generic blowfish_generic blowfish_common 
cast5 serpent twofish_generic twofish_i586 twofish_common aes_i586 aes_generic 
cbc ipsec(O-) ip_gre netconsole configfs xt_comment ipt_REDIRECT 
ipt_MASQUERADE ipip tunnel4 pppoatm xt_TCPMSS xt_connmark nf_nat_proto_sctp 
nf_nat_proto_udplite nf_nat_pptp nf_nat_proto_gre nf_nat_h323 nf_nat_irc 
nf_nat_proto_dccp nf_nat_ftp ts_kmp nf_conntrack_proto_dccp 
nf_conntrack_proto_sctp nf_conntrack_pptp nf_conntrack_irc 
nf_conntrack_netlink nf_conntrack_h323 nf_conntrack_ftp 
nf_conntrack_netbios_ns nf_conntrack_sane nf_conntrack_proto_udplite 
nf_conntrack_snmp nf_conntrack_proto_gre nf_conntrack_broadcast ipt_REJECT 
ipt_LOG xt_limit xt_tcpudp xt_state xt_mark nfnetlink_queue nfnetlink 
ip6table_filter ip6_tables iptable_mangle iptable_nat nf_nat nf_conntrack_ipv4 
nf_defrag_ipv4 iptable_filter ip_tables x_tables nf_conntrack ppp_deflate 
zlib_deflate bsd_comp ppp_generic slhc unicorn_pci_atm(P) atm e1000 e1000e(O) 
8139too mii ftdi_sio usbserial dm_mod usbhid uhci_hcd ohci_hcd ehci_hcd 
usbcore usb_common [last unloaded: pl2303]
Pid: 3558, comm: rmmod Tainted: P        W  O 3.2-axs-1 #1
Call Trace:
 [<c1031ead>] warn_slowpath_common+0x6d/0xa0
 [<c10f5bc3>] ? remove_proc_entry+0x193/0x1f0
 [<c10f5bc3>] ? remove_proc_entry+0x193/0x1f0
 [<c1031f5e>] warn_slowpath_fmt+0x2e/0x30
 [<c10f5bc3>] remove_proc_entry+0x193/0x1f0
 [<f974a046>] ? backport_proc_subdir_remove+0x26/0x30 [ipsec]
 [<f974a144>] remove_proc_subtree+0x44/0x50 [ipsec]
 [<f974b800>] pfkey_cleanup+0x80/0x90 [ipsec]
 [<f97362ec>] cleanup_module+0xcc/0x190 [ipsec]
 [<c105e342>] ? module_refcount+0x72/0x90
 [<c105f577>] sys_delete_module+0x107/0x250
 [<c1090063>] ? vma_adjust+0x343/0x4d0
 [<c1321f75>] syscall_call+0x7/0xb
---[ end trace 6cba7fefe657526b ]---
------------[ cut here ]------------

In openswan/linux/net/ipsec/pfkey_v2.c a backport is introduced for 
remove_proc_subtree courtesy Louis R. Rodriguez (not Al Viro) [2]. This patch 
[2] however was never accepted upstream, and as detailed in [3] it is 
incorrectly removing all items recursively under the given proc path (Al Viro).

Since only proc files are being removed, not directories, I suggest to map the 
behaviour for remove_proc_subtree onto remove_proc_entry for older kernels 
(also similar to libreswan).

[1]. https://github.com/xelerance/Openswan/issues/65
[2]. http://www.spinics.net/lists/backports/msg01185.html
[3]. http://www.spinics.net/lists/backports/msg01189.html

Singed-off-by: Tijs Van Buggenhout <tijs.van.buggenhout at able.be>
--

--- a/linux/include/openswan/ipsec_kversion.h
+++ b/linux/include/openswan/ipsec_kversion.h
@@ -62,6 +62,14 @@
 # define RHEL_RELEASE_VERSION(x,y) 10
 #endif
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0)
+#ifdef CONFIG_PROC_FS
+# define remove_proc_subtree(a,b) remove_proc_entry(a,b)
+#else
+#define remove_proc_subtree(name, parent) do {} while (0)
+#endif /* CONFIG_PROC_FS */
+#endif
+
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0)
 # define ipsec_ipv6_skip_exthdr ipv6_skip_exthdr
 # define IPSEC_FRAG_OFF_DECL(x) __be16 x;
--- a/linux/net/ipsec/pfkey_v2.c
+++ b/linux/net/ipsec/pfkey_v2.c
@@ -207,50 +207,6 @@ static __inline__ void pfkey_unlock_sock
 }
 #endif
 
-/*****
-Grabbed Mr. Viro's proc_subtree backport code for older kernels
-commit 8ce584c7416d8a85a6f3edc17d1cddefe331e87e
-Author: Al Viro <v... at zeniv.linux.org.uk>
-Date:   Sat Mar 30 20:13:46 2013 -0400
-****/
-#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
-#ifdef CONFIG_PROC_FS
-
-static void backport_proc_subdir_remove(struct proc_dir_entry *dir)
-{
-       struct proc_dir_entry *pe, *tmp;
-       pe = dir->subdir;
-       while (pe) {
-               tmp = pe->next;
-               backport_proc_subdir_remove(pe);
-               remove_proc_entry(pe->name, dir);
-               pe = tmp;
-       }
-};
-
-int remove_proc_subtree(const char *name, struct proc_dir_entry *parent)
-{
-       struct proc_dir_entry *pe, *tmp;
-
-       if (!parent)
-               goto out;
-
-       pe = parent->subdir;
-       while (pe) {
-               tmp = pe->next;
-               backport_proc_subdir_remove(pe);
-               remove_proc_entry(pe->name, parent);
-               pe = tmp;
-       }
-
-out:
-       remove_proc_entry(name, parent);
-
-       return 0;
-}
-#endif /* CONFIG_PROC_FS */
-#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0) */
-
 int
 pfkey_list_remove_socket(struct socket *socketp, struct socket_list **sockets)
 {
@@ -1498,11 +1454,11 @@ pfkey_init(void)
         {
                 struct proc_dir_entry* entry;
 
-                entry = create_proc_entry ("pf_key", 0, init_net.proc_net);
+                entry = create_proc_entry ("pf_key", 0, PROC_NET);
                 entry->read_proc = pfkey_get_info;
-                entry = create_proc_entry ("pf_key_supported", 0, init_net.proc_net);
+                entry = create_proc_entry ("pf_key_supported", 0, PROC_NET);
                 entry->read_proc = pfkey_supported_get_info;
-                entry = create_proc_entry ("pf_key_registered", 0, init_net.proc_net);
+                entry = create_proc_entry ("pf_key_registered", 0, PROC_NET);
                 entry->read_proc = pfkey_registered_get_info;
         }
 #endif /* CONFIG_PROC_FS */
@@ -1530,9 +1486,9 @@ pfkey_cleanup(void)
 	error |= supported_remove_all(K_SADB_X_SATYPE_IPIP);
 
 #ifdef CONFIG_PROC_FS
-        remove_proc_subtree("pf_key",            init_net.proc_net);
-        remove_proc_subtree("pf_key_supported",  init_net.proc_net);
-        remove_proc_subtree("pf_key_registered", init_net.proc_net);
+        remove_proc_subtree("pf_key",            PROC_NET);
+        remove_proc_subtree("pf_key_supported",  PROC_NET);
+        remove_proc_subtree("pf_key_registered", PROC_NET);
 #endif /* CONFIG_PROC_FS */
 
 	/* other module unloading cleanup happens here */



More information about the Dev mailing list