netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: Thomas Graf <tgraf@suug.ch>
Cc: nagar@watson.ibm.com, jlan@sgi.com, pj@sgi.com,
	Valdis.Kletnieks@vt.edu, balbir@in.ibm.com, csturtiv@sgi.com,
	linux-kernel@vger.kernel.org, hadi@cyberus.ca,
	netdev@vger.kernel.org
Subject: Re: [PATCH] per-task delay accounting taskstats interface: control exit data through cpumasks]
Date: Thu, 6 Jul 2006 16:05:57 -0700	[thread overview]
Message-ID: <20060706160557.6f0cdfa0.akpm@osdl.org> (raw)
In-Reply-To: <20060706224009.GA14627@postel.suug.ch>

Thomas Graf <tgraf@suug.ch> wrote:
>
> * Andrew Morton <akpm@osdl.org> 2006-07-06 14:48
> > In the interests of keeping this work decoupled from netlink enhancements
> > I'd propose the below.  Is it bad to modify the data at nla_data()?
> 
> Yes, it points into a skb data buffer which may be shared by sitting
> on other queues if the message is to be broadcasted. In this case it
> would be harmless but the policy is to leave it unmodified.

Yup, sleazy-but-safe.

> 
> > --- a/kernel/taskstats.c~per-task-delay-accounting-taskstats-interface-control-exit-data-through-cpumasks-fix
> > +++ a/kernel/taskstats.c
> > @@ -299,6 +299,23 @@ cleanup:
> >  	return 0;
> >  }
> >  
> > +static int parse(struct nlattr *na, cpumask_t *mask)
> > +{
> > +	char *data;
> > +	int len;
> > +
> > +	if (na == NULL)
> > +		return 1;
> > +	len = nla_len(na);
> > +	if (len > TASKSTATS_CPUMASK_MAXLEN)
> > +		return -E2BIG;
> > +	if (len < 1)
> > +		return -EINVAL;
> > +	data = nla_data(na);
> > +	data[len - 1] = '\0';
> > +	return cpulist_parse(data, *mask);
> > +}
> 
> Usually this is done by using strlcpy:

hm, nla_strlcpy() looks more complex than it needs to be.  We really need
nla_kstrndup() ;)

Oh well.  This?


diff -puN kernel/taskstats.c~per-task-delay-accounting-taskstats-interface-control-exit-data-through-cpumasks-fix kernel/taskstats.c
--- a/kernel/taskstats.c~per-task-delay-accounting-taskstats-interface-control-exit-data-through-cpumasks-fix
+++ a/kernel/taskstats.c
@@ -299,6 +299,28 @@ cleanup:
 	return 0;
 }
 
+static int parse(struct nlattr *na, cpumask_t *mask)
+{
+	char *data;
+	int len;
+	int ret;
+
+	if (na == NULL)
+		return 1;
+	len = nla_len(na);
+	if (len > TASKSTATS_CPUMASK_MAXLEN)
+		return -E2BIG;
+	if (len < 1)
+		return -EINVAL;
+	data = kmalloc(len, GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+	nla_strlcpy(data, na, len);
+	ret = cpulist_parse(data, *mask);
+	kfree(data);
+	return ret;
+}
+
 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
 {
 	int rc = 0;
@@ -309,27 +331,17 @@ static int taskstats_user_cmd(struct sk_
 	struct nlattr *na;
 	cpumask_t mask;
 
-	if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK]) {
-		na = info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK];
-		if (nla_len(na) > TASKSTATS_CPUMASK_MAXLEN)
-			return -E2BIG;
-		rc = cpulist_parse((char *)nla_data(na), mask);
-		if (rc)
-			return rc;
-		rc = add_del_listener(info->snd_pid, &mask, REGISTER);
+	rc = parse(info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK], &mask);
+	if (rc < 0)
 		return rc;
-	}
+	if (rc == 0)
+		return add_del_listener(info->snd_pid, &mask, REGISTER);
 
-	if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK]) {
-		na = info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK];
-		if (nla_len(na) > TASKSTATS_CPUMASK_MAXLEN)
-			return -E2BIG;
-		rc = cpulist_parse((char *)nla_data(na), mask);
-		if (rc)
-			return rc;
-		rc = add_del_listener(info->snd_pid, &mask, DEREGISTER);
+	rc = parse(info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK], &mask);
+	if (rc < 0)
 		return rc;
-	}
+	if (rc == 0)
+		return add_del_listener(info->snd_pid, &mask, DEREGISTER);
 
 	/*
 	 * Size includes space for nested attributes
_


  reply	other threads:[~2006-07-06 23:12 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-06  9:28 [PATCH] per-task delay accounting taskstats interface: control exit data through cpumasks] Shailabh Nagar
2006-07-06  9:56 ` Andrew Morton
2006-07-06 10:44   ` Shailabh Nagar
2006-07-06 11:37   ` Shailabh Nagar
2006-07-06 12:08     ` Thomas Graf
2006-07-06 13:21       ` Shailabh Nagar
2006-07-06 21:48       ` Andrew Morton
2006-07-06 22:27         ` Shailabh Nagar
2006-07-06 22:56           ` Andrew Morton
2006-07-07 10:21             ` Thomas Graf
2006-07-06 22:40         ` Thomas Graf
2006-07-06 23:05           ` Andrew Morton [this message]
2006-07-07 10:16             ` Thomas Graf
2006-07-07  6:18   ` Paul Jackson

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=20060706160557.6f0cdfa0.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=Valdis.Kletnieks@vt.edu \
    --cc=balbir@in.ibm.com \
    --cc=csturtiv@sgi.com \
    --cc=hadi@cyberus.ca \
    --cc=jlan@sgi.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nagar@watson.ibm.com \
    --cc=netdev@vger.kernel.org \
    --cc=pj@sgi.com \
    --cc=tgraf@suug.ch \
    /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).