netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ss: prepare rth when killing inet sock
@ 2018-02-14 13:50 Masatake YAMATO
  2018-02-14 15:25 ` Stephen Hemminger
  0 siblings, 1 reply; 2+ messages in thread
From: Masatake YAMATO @ 2018-02-14 13:50 UTC (permalink / raw)
  To: netdev; +Cc: yamato

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.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
 misc/ss.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/misc/ss.c b/misc/ss.c
index 29a25070..a59fa2c1 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -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:
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-02-14 15:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-14 13:50 [PATCH] ss: prepare rth when killing inet sock Masatake YAMATO
2018-02-14 15:25 ` Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).