netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: richard.alpe@ericsson.com
Cc: netdev@vger.kernel.org, tipc-discussion@lists.sourceforge.net
Subject: Re: [PATCH net-next 04/14] tipc: add sock dump to new netlink api
Date: Fri, 12 Sep 2014 17:10:38 -0400 (EDT)	[thread overview]
Message-ID: <20140912.171038.1165432718811920305.davem@davemloft.net> (raw)
In-Reply-To: <1410424167-17427-5-git-send-email-richard.alpe@ericsson.com>

From: <richard.alpe@ericsson.com>
Date: Thu, 11 Sep 2014 10:29:17 +0200

> +	list_for_each_entry_from(p, &tsk->publications, pport_list) {
> +		publ = nla_nest_start(skb, TIPC_NLA_SOCK_PUBL);
> +		if (nla_put_u32(skb, TIPC_NLA_PUBL_TYPE, p->type))
> +			goto msg_full;
> +		if (nla_put_u32(skb, TIPC_NLA_PUBL_LOWER, p->lower))
> +			goto msg_full;
> +		if (nla_put_u32(skb, TIPC_NLA_PUBL_UPPER, p->upper))
> +			goto msg_full;
> +		nla_nest_end(skb, publ);
> +	}
> +
> +	*prev_publ = 0;
> +
> +	return 0;
> +
> +msg_full:
> +	*prev_publ = p->key;
> +	nla_nest_cancel(skb, publ);

This restart mechanism is broken.

You can't public nested information this way.

What happens in your code is that if we hit the limit in the middle of
adding the publications, the next time we'll put the same socket into
the netlink message and then the rest of the nested publications.
That's malformed.

You can't just say sometimes you'll partially list the set of nested
attributes in an object, you must public the entire object fully in
the netlink message or skip the object entirely.

I would suggest that you instead size the amount of space you'll
need for at least the first socket being listed, and if NLMSG_GOODSIZE
is insufficient, allocate as much as you will actually need.

Then you put full socket netlink blobs in there, including all nested
attributes, and then stop and reset back the the most recent full socket
published if you run out of space.

  reply	other threads:[~2014-09-12 21:10 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-11  8:29 [PATCH net-next 00/14] tipc: new netlink API richard.alpe
2014-09-11  8:29 ` [PATCH net-next 01/14] tipc: add bearer disable/enable to new netlink api richard.alpe
2014-09-12 21:07   ` David Miller
2014-09-11  8:29 ` [PATCH net-next 02/14] tipc: add bearer get/dump " richard.alpe
2014-09-11  8:29 ` [PATCH net-next 03/14] tipc: add bearer set " richard.alpe
2014-09-11  8:29 ` [PATCH net-next 04/14] tipc: add sock dump " richard.alpe
2014-09-12 21:10   ` David Miller [this message]
2014-09-15  7:55     ` Richard Alpe
2014-09-15  8:51       ` Florian Westphal
2014-09-15 12:35         ` Richard Alpe
2014-09-15 15:38       ` David Miller
2014-09-15 16:35         ` Jon Maloy
2014-09-23 11:12         ` Richard Alpe
2014-09-23 15:37           ` David Miller
2014-09-11  8:29 ` [PATCH net-next 05/14] tipc: add link get/dump " richard.alpe
2014-09-11  8:29 ` [PATCH net-next 06/14] tipc: add link set " richard.alpe
2014-09-11  8:29 ` [PATCH net-next 07/14] tipc: add link stat reset " richard.alpe
2014-09-11  8:29 ` [PATCH net-next 08/14] tipc: add media get/dump " richard.alpe
2014-09-11  8:29 ` [PATCH net-next 09/14] tipc: add media set " richard.alpe
2014-09-11  8:29 ` [PATCH net-next 10/14] tipc: add node get/dump " richard.alpe
2014-09-11  8:29 ` [PATCH net-next 11/14] tipc: add net dump " richard.alpe
2014-09-11  8:29 ` [PATCH net-next 12/14] tipc: add net set " richard.alpe
2014-09-11  8:29 ` [PATCH net-next 13/14] tipc: add name table dump " richard.alpe
2014-09-11  8:29 ` [PATCH net-next 14/14] tipc: remove old ASCII netlink API richard.alpe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140912.171038.1165432718811920305.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=richard.alpe@ericsson.com \
    --cc=tipc-discussion@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).