[PATCH v7 4/4] Netlink: handle multi netlink messages

Dmitry V. Levin ldv at altlinux.org
Thu Jun 23 11:36:25 UTC 2016


On Thu, Jun 23, 2016 at 10:49:53AM +0000, Fabien Siron wrote:
> Quoting Dmitry V. Levin (2016-06-22 17:40:39)
> > On Wed, Jun 22, 2016 at 01:27:06PM +0000, Fabien Siron wrote:
> [...]
> > > +static int
> > > +nlmsg_fetch(struct tcb *tcp, struct nlmsghdr *nlmsghdr, unsigned long addr,
> > > +         unsigned long len) {
> > > +     if (len < sizeof(struct nlmsghdr)) {
> > > +             if (len != 0)
> > > +                     printstr(tcp, addr, len);
> > > +             return 0;
> > > +     }
> > > +
> > > +     if (umove_or_printaddr(tcp, addr, nlmsghdr) == -1)
> > > +             return 0;
> > > +
> > > +     if (len < nlmsghdr->nlmsg_len) {
> > > +             printstr(tcp, addr, len);
> > > +             return 0;
> > > +     }
> > 
> > I think that if struct nlmsghdr has been successfully fetched,
> > the header should be printed regardless of its nlmsg_len.
> 
> So you actually want to remove the last test?

Yes, and rename this function to fetch_nlmsghdr.

> > > +     return 1;
> > > +}
> > >  
> > > +static unsigned long
> > > +nlmsg_next(struct nlmsghdr *nlmsghdr, unsigned long addr, unsigned long *len) {

Ditto, next_nlmsghdr.

> > > +     if (NLMSG_ALIGN(nlmsghdr->nlmsg_len) == 0 ||
> > > +         NLMSG_ALIGN(nlmsghdr->nlmsg_len) > *len)
> > > +             return 0;
> > 
> > This is not going to happen with current implementation of nlmsg_fetch,
> > but if nlmsg_fetch changes and if this condition is true, then
> > *len remains unchanged and the subsequent nlmsg_fetch prints NULL.
> 
> A way to fix that is to put *len to 0 in this test. But the problem is that
> nothing will be printed if sizeof(struct nlmsghdr) < *len < nlmsghdr->nlmsg_len.

It's up to decode_netlink_msg to decide how to print such messages.

decode_netlink has to be consistent.  Every successfully fetched struct
nlmsghdr should be printed.  When decode_netlink leaves some bytes of the
message undecoded, it has to print an indication.


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20160623/2833a580/attachment.bin>


More information about the Strace-devel mailing list