linux_proc pmda: correct stack blowage during ioctl() for network interfaces
linux_proc pmda: correct stack blowage during ioctl() for network interfaces

We finally isolated the cause of the peculiar stack-segment
supergrowth seen occasionally for pmcd on linux, wherein
multi-gigabyte stacks sometimes briefly appeared on x86-64 hosts.
Some analysis with systemtap [1] helped pinpoint the linux_proc
network ioctl()s as causing the problem.  The problem appears to be
the corruption of the ioctl-argument ifr->ecmd pointer between
consecutive ioctl()s.  This is now corrected by reinitializing
before each ioctl().

[1] # stap -e '
probe kernel.function("acct_stack_growth") {
   if (execname()=="pmcd") {
      println (pn(), " ", $$parms)
      print_backtrace()
      print_ubacktrace()
   }
}' -d /usr/libexec/pcp/bin/pmcd -d /var/lib/pcp/pmdas/linux/pmda_linux.so --ldd

Which reported, inter alia,

kernel.function("acct_stack_growth@mm/mmap.c:2035") grow=0x17d92 size=0x17db4000 vma=0xffff88009d80b000
 0xffffffff8116c560 : expand_downwards+0xb0/0x240 [kernel]
 0xffffffff8116c714 : expand_stack+0x24/0x40 [kernel]
 0xffffffff8165207f : __do_page_fault+0x43f/0x510 [kernel]
 0xffffffff8165215e : do_page_fault+0xe/0x10 [kernel]
 0xffffffff8164e6d8 : page_fault+0x28/0x30 [kernel]
 0xffffffff81306ae5 : copy_user_generic_string+0x35/0x40 [kernel]
 0xffff88009d8bfe18
 0xffffffff812a72ec : sidtab_context_to_sid+0x30c/0x480 [kernel] (inexact)
 0xffffffff8154a399 : dev_get_by_name_rcu+0x69/0x90 [kernel] (inexact)
 0xffffffff8155f56b : dev_ioctl+0x1ab/0x560 [kernel] (inexact)
 0xffffffff81634d02 : netlbl_domhsh_hash+0x12/0x50 [kernel] (inexact)
 0xffffffff8129e7fc : selinux_file_alloc_security+0x3c/0x60 [kernel] (inexact)
 0xffffffff81531195 : sock_do_ioctl+0x45/0x50 [kernel] (inexact)
 0xffffffff815315e0 : sock_ioctl+0x1f0/0x2c0 [kernel] (inexact)
 0xffffffff811b9fdd : do_vfs_ioctl+0x2dd/0x4b0 [kernel] (inexact)
 0xffffffffa0ecba01 [stap_ee080e3c411678e5f019bf218d63791_23997] (inexact)
 0xffffffff811ba231 : SyS_ioctl+0x81/0xa0 [kernel] (inexact)
 0xffffffff81656aa7 : tracesys+0xdd/0xe2 [kernel] (inexact)
 0x2ba833548eb7 : ioctl+0x7/0x30 [/usr/lib64/libc-2.17.so]
 0x2ba8368cfee6 : refresh_proc_net_dev+0x256/0x590 [/var/lib/pcp/pmdas/linux/pmda_linux.so]
 0x2ba8368c9e2b : linux_refresh+0x39b/0x450 [/var/lib/pcp/pmdas/linux/pmda_linux.so]
 0x2ba8368c9fe8 : linux_fetch+0x108/0x170 [/var/lib/pcp/pmdas/linux/pmda_linux.so]
 0x2ba832bbcdf5 : DoFetch+0x585/0x1460 [/usr/libexec/pcp/bin/pmcd]
 0x2ba832bb6a8b : HandleClientInput+0x28b/0x510 [/usr/libexec/pcp/bin/pmcd]
 0x2ba832bb6f03 : ClientLoop+0x1f3/0x6b0 [/usr/libexec/pcp/bin/pmcd]
 0x2ba832bb5a2b : main+0x5db/0x7c0 [/usr/libexec/pcp/bin/pmcd]
 0x2ba83347db45 : __libc_start_main+0xf5/0x1c0 [/usr/lib64/libc-2.17.so]
 0x2ba832bb5c39 : _start+0x29/0x30 [/usr/libexec/pcp/bin/pmcd]

prasincs/pcp,andyvand/cygpcpfans,prasincs/pcp,wuliming/pcp,aeg-aeg/pcpfans,edwardt/pcp,adfernandes/pcp,edwardt/pcp,aeg-aeg/pcpfans,aeg-aeg/pcpfans,andyvand/cygpcpfans,tjanez/pcp,tjanez/pcp,prasincs/pcp,edwardt/pcp,mbaldessari/pcp,tjanez/pcp,wuliming/pcp,adfernandes/pcp,andyvand/cygpcpfans,prasincs/pcp,andyvand/cygpcpfans,tjanez/pcp,wuliming/pcp,tjanez/pcp,wuliming/pcp,mbaldessari/pcp,aeg-aeg/pcpfans,andyvand/cygpcpfans,mbaldessari/pcp,andyvand/cygpcpfans,adfernandes/pcp,aeg-aeg/pcpfans,wuliming/pcp,wuliming/pcp,prasincs/pcp,prasincs/pcp,adfernandes/pcp,prasincs/pcp,edwardt/pcp,prasincs/pcp,edwardt/pcp,wuliming/pcp,adfernandes/pcp,adfernandes/pcp,aeg-aeg/pcpfans,aeg-aeg/pcpfans,andyvand/cygpcpfans,mbaldessari/pcp,tjanez/pcp,tjanez/pcp,edwardt/pcp,andyvand/cygpcpfans,wuliming/pcp,adfernandes/pcp,tjanez/pcp,adfernandes/pcp,edwardt/pcp,edwardt/pcp,mbaldessari/pcp,aeg-aeg/pcpfans,mbaldessari/pcp