netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Graf <tgraf@suug.ch>
To: "Rémi Denis-Courmont" <remi.denis-courmont@nokia.com>
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH 05/11] Phonet: Netlink interface
Date: Tue, 23 Sep 2008 14:10:02 +0200	[thread overview]
Message-ID: <20080923121002.GQ20815@postel.suug.ch> (raw)
In-Reply-To: <1222098445-26175-5-git-send-email-remi.denis-courmont@nokia.com>

Hello!

* R?mi Denis-Courmont <remi.denis-courmont@nokia.com> 2008-09-22 18:47
> +static int newaddr_doit(struct sk_buff *skb, struct nlmsghdr *nlm, void *attr)
> +{
> +	struct rtattr **rta = attr;
> +	struct ifaddrmsg *ifm = NLMSG_DATA(nlm);
> +	struct net_device *dev;
> +	int err;
> +	u8 pnaddr;
> +
> +	if (!capable(CAP_SYS_ADMIN))
> +		return -EPERM;
> +
> +	ASSERT_RTNL();
> +
> +	if (rta[IFA_LOCAL - 1] == NULL)
> +		return -EINVAL;

Please do not use the old attribute buffer anymore. It's use is racy
ever since we started dropping the rtnl semaphore in order to load
modules. It would be safe in this particular case but it shouldn't be
used for new code.

Take a look at rtnl_setlink() for an example on how to use the interface
correctly.

> +	memcpy(&pnaddr, RTA_DATA(rta[IFA_LOCAL - 1]), 1);

This is not safe, the attribute payload needs to be verified before its
use.

Please use the new netlink interface, all functions named RTA_ or rattr_
are deprecated. The new interface provides a trivial method to validate
attributes while they are being parsed.

> +static int fill_addr(struct sk_buff *skb, struct net_device *dev, u8 addr,
> +			u32 pid, u32 seq, int event)
> +{
> +	struct ifaddrmsg *ifm;
> +	struct nlmsghdr *nlh;
> +	unsigned int orig_len = skb->len;
> +
> +	nlh = NLMSG_PUT(skb, pid, seq, event, sizeof(struct ifaddrmsg));
> +	ifm = NLMSG_DATA(nlh);

Please use nlmsg_put() and nlmsg_data()

> +	ifm->ifa_family = AF_PHONET;
> +	ifm->ifa_prefixlen = 0;
> +	ifm->ifa_flags = IFA_F_PERMANENT;
> +	ifm->ifa_scope = RT_SCOPE_HOST;
> +	ifm->ifa_index = dev->ifindex;
> +	RTA_PUT(skb, IFA_LOCAL, 1, &addr);
> +	nlh->nlmsg_len = skb->len - orig_len;

See rtnl_fill_ifinfo() for an example.

  reply	other threads:[~2008-09-23 12:09 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-22 15:45 [PATCH 00/11] PhoNet protocols stack v2 Rémi Denis-Courmont
2008-09-22 15:47 ` [PATCH 01/11] Phonet global definitions Rémi Denis-Courmont
2008-09-22 15:47 ` [PATCH 02/11] Phonet: PF_PHONET protocol family support Rémi Denis-Courmont
2008-09-22 15:47 ` [PATCH 03/11] Phonet: add CONFIG_PHONET Rémi Denis-Courmont
2008-09-22 15:47 ` [PATCH 04/11] Phonet: network device and address handling Rémi Denis-Courmont
2008-09-22 15:47 ` [PATCH 05/11] Phonet: Netlink interface Rémi Denis-Courmont
2008-09-23 12:10   ` Thomas Graf [this message]
2008-09-24 11:30     ` Rémi Denis-Courmont
2008-09-24 13:23       ` Thomas Graf
2008-09-22 15:47 ` [PATCH 06/11] Phonet: common socket glue Rémi Denis-Courmont
2008-09-22 15:47 ` [PATCH 07/11] Phonet: Phonet datagram transport protocol Rémi Denis-Courmont
2008-09-22 15:47 ` [PATCH 08/11] Phonet: provide MAC header operations Rémi Denis-Courmont
2008-09-22 15:47 ` [PATCH 09/11] Phonet: proc interface for port range Rémi Denis-Courmont
2008-09-22 15:47 ` [PATCH 10/11] Phonet: emit errors when a packet cannot be delivered locally Rémi Denis-Courmont
2008-09-22 15:47 ` [PATCH 11/11] Phonet: kernel documentation Rémi Denis-Courmont
2008-09-23 21:43   ` Randy Dunlap
2008-09-24 12:15     ` [PATCH] Phonet: improve documentation Rémi Denis-Courmont
2008-09-24 15:45       ` Randy Dunlap
2008-09-23  3:16 ` [PATCH 00/11] PhoNet protocols stack v2 David Miller

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=20080923121002.GQ20815@postel.suug.ch \
    --to=tgraf@suug.ch \
    --cc=netdev@vger.kernel.org \
    --cc=remi.denis-courmont@nokia.com \
    /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).