ss: prepare rth when killing inet sock
Subsystems (2)
PATCH 1/1 ss: prepare rth when killing inet sock
kill_inet_sock() expects rhn_handle instance is passed via inet_diag_arg argument. However on the following calling path:
generic_show_sock
=> show_one_inet_sock
=> kill_inet_sock
rth field of inet_diag_arg is not filled with the address of rhn_handle instance. As the result ss crashes.
This commit fills the field with newly created rhn_handle instance.
--- misc/ss.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
misc/ss.c +8 -1
@@ -4258,11 +4258,18 @@ static int generic_show_sock(const struct sockaddr_nl *addr, {struct sock_diag_msg *r =NLMSG_DATA (nlh);struct inet_diag_arg inet_arg = { .f = arg, .protocol =IPPROTO_MAX }; +struct rtnl_handle rth_inet; +int result_inet;switch (r->sdiag_family) {case AF_INET :case AF_INET6 : -return show_one_inet_sock (addr, nlh, &inet_arg); +if (rtnl_open_byproto (&rth_inet,0 ,NETLINK_SOCK_DIAG )) +return -1 ; + inet_arg.rth = &rth_inet; + result_inet =show_one_inet_sock (addr, nlh, &inet_arg); +rtnl_close (&rth_inet); +return result_inet;case AF_UNIX :return unix_show_sock (addr, nlh, arg);case AF_PACKET :
Signature · 1 line
2.14.3
Quoted 7 lines · On Wed, 14 Feb 2018 22:50:04 +0900 Masatake YAMATO <[email protected]> wrote:
kill_inet_sock()expectsrhn_handleinstance is passed viainet_diag_argargument. However on the following calling path:
generic_show_sock
=>show_one_inet_sock
=>kill_inet_sock
Quoted 7 lines
rth field of
inet_diag_argis not filled with the address ofrhn_handleinstance. As the result ss crashes.This commit fills the field with newly created
rhn_handleinstance.Signed-off-by Masatake YAMATO <[email protected]>
Won't this slow down ss because it does open/close of netlink socket for each socket being displayed. It is not uncommon to run this with millions of sockets open.