[PATCH] netlink: add type decoding

JingPiao Chen chenjingpiao at gmail.com
Mon Jun 5 07:07:04 UTC 2017


On Sun, Jun 04, 2017 at 10:40:09PM +0300, Dmitry V. Levin wrote:
> On Mon, Jul 11, 2016 at 12:54:59PM +0000, Fabien Siron wrote:
> > Decode and print the type of the main netlink protocols.
> 
> JingPiao Chen, I've reworked Fabien's commits from your netlink branch
> up to and including this one (52dc63cc "netlink: add type decoding")
> for merge into master.  I've pushed them to ldv/netlink branch
> and now waiting for a new version of your
> "tests: add check for nlmsg_type decoding" commit to test these changes.
> 
> A few notes about Fabien's code that might be useful for your netlink efforts:
> 
> > @@ -96,7 +96,8 @@ print_iovec(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
> >  				len = c->data_size;
> >  			if (c->data_size != (kernel_ulong_t) -1)
> >  				c->data_size -= len;
> > -			decode_netlink(tcp, iov[0], len);
> > +			decode_netlink(tcp, *(int *)c->optional_data,
> > +				       iov[0], len);
> >  			break;
> >  		default:
> >  			printaddr(iov[0]);
> > @@ -354,7 +354,7 @@ print_struct_msghdr(struct tcb *tcp, const struct msghdr *msg,
> >  	tprints(", msg_iov=");
> >  
> >  	tprint_iov_upto(tcp, msg->msg_iovlen, ptr_to_kulong(msg->msg_iov),
> > -			decode, data_size, NULL);
> > +			decode, data_size, &tcp->u_arg[0]);
> >  	tprintf(", msg_iovlen=%" PRI_klu, (kernel_ulong_t) msg->msg_iovlen);
> >  
> >  	decode_msg_control(tcp, ptr_to_kulong(msg->msg_control),
> 
> If sizeof(tcp->u_arg[0]) > sizeof(int), a wrong value will be passed to decode_netlink.

Thank you.

[...]
> 
> Well, not exactly into this because NETLINK_NETFILTER message types are not as
> simple (even more complex than Fabien thought when he wrote this code).
> 
> > @@ -132,20 +196,21 @@ decode_payload(struct tcb *const tcp,
> >  }
> >  
> >  static void
> > -decode_nlmsghdr_with_payload(struct tcb *const tcp,
> > +decode_nlmsghdr_with_payload(struct tcb *const tcp, int fd,
> >  			     const struct nlmsghdr *const nlmsghdr,
> >  			     const kernel_ulong_t addr,
> >  			     const kernel_ulong_t len)
> >  {
> >  	tprints("{");
> >  
> > -	print_nlmsghdr(tcp, nlmsghdr);
> > +	int proto = getfdnlproto(tcp, fd, netlink_protocols);
> > +	print_nlmsghdr(tcp, nlmsghdr, proto);
> 
> getfdnlproto (get_fd_nl_family in my edition) is not cheap
> (it invokes syscalls), needless calls should be avoided.

I have read your code, I will rebase my code after you merge
ldv/netlink branch.

--
JingPiao Chen




More information about the Strace-devel mailing list