From: Chen Gang <gang.chen@asianux.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Michael Kerrisk <mtk.manpages@gmail.com>
Subject: Re: [PATCH] kernel/groups.c: consider about NULL for 'group_info' in all related extern functions
Date: Tue, 03 Sep 2013 13:23:20 +0800 [thread overview]
Message-ID: <52257248.9080508@asianux.com> (raw)
In-Reply-To: <5212DC65.9080702@asianux.com>
Hello Maintainers:
Please help check this patch, when you have time.
If need a related test, please let me know, I should try (better to
provide some suggestions for test).
Thanks.
On 08/20/2013 11:03 AM, Chen Gang wrote:
>
> If this patch is correct, also need modify the man page for the return
> value of getgroups().
>
> Thanks.
>
> On 08/20/2013 11:01 AM, Chen Gang wrote:
>> groups_alloc() can return NULL for 'group_info', also group_search()
>> already considers about NULL for 'group_info', so can assume the caller
>> has right to use all related extern functions when 'group_info' is NULL.
>>
>> For groups_free(), need check NULL to match groups_alloc(), just like
>> kmalloc/free().
>>
>> For set_groups(), can allow the caller to set NULL parameter to new
>> 'cred'.
>>
>> For system call getgroups(), if 'cred->group_info' is NULL, need return
>> the related error code (no related data), also need change the related
>> man page ("man 2 getgroups") to complete the return value.
>>
>>
>> Signed-off-by: Chen Gang <gang.chen@asianux.com>
>> ---
>> kernel/groups.c | 14 +++++++++++---
>> 1 files changed, 11 insertions(+), 3 deletions(-)
>>
>> diff --git a/kernel/groups.c b/kernel/groups.c
>> index 6b2588d..a21a4ce 100644
>> --- a/kernel/groups.c
>> +++ b/kernel/groups.c
>> @@ -52,6 +52,9 @@ EXPORT_SYMBOL(groups_alloc);
>>
>> void groups_free(struct group_info *group_info)
>> {
>> + if (!group_info)
>> + return;
>> +
>> if (group_info->blocks[0] != group_info->small_block) {
>> int i;
>> for (i = 0; i < group_info->nblocks; i++)
>> @@ -163,9 +166,12 @@ int groups_search(const struct group_info
>> *group_info, kgid_t grp)
>> */
>> int set_groups(struct cred *new, struct group_info *group_info)
>> {
>> - put_group_info(new->group_info);
>> - groups_sort(group_info);
>> - get_group_info(group_info);
>> + if (new->group_info)
>> + put_group_info(new->group_info);
>> + if (group_info) {
>> + groups_sort(group_info);
>> + get_group_info(group_info);
>> + }
>> new->group_info = group_info;
>> return 0;
>> }
>> @@ -206,6 +212,8 @@ SYSCALL_DEFINE2(getgroups, int, gidsetsize, gid_t
>> __user *, grouplist)
>>
>> if (gidsetsize < 0)
>> return -EINVAL;
>> + if (!cred->group_info)
>> + return -ENODATA;
>>
>> /* no need to grab task_lock here; it cannot change */
>> i = cred->group_info->ngroups;
>>
>
>
--
Chen Gang
next prev parent reply other threads:[~2013-09-03 5:24 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-20 3:01 [PATCH] kernel/groups.c: consider about NULL for 'group_info' in all related extern functions Chen Gang
2013-08-20 3:03 ` Chen Gang
2013-09-03 5:23 ` Chen Gang [this message]
2013-09-23 15:06 ` Tejun Heo
2013-09-24 3:42 ` Chen Gang
2013-09-24 4:06 ` Tejun Heo
2013-09-24 4:27 ` Chen Gang
2013-09-24 12:04 ` Tejun Heo
2013-09-25 0:49 ` Chen Gang
2013-09-25 0:58 ` Tejun Heo
2013-09-25 1:06 ` Chen Gang
2013-09-25 1:14 ` Tejun Heo
2013-09-25 1:47 ` Chen Gang
2013-09-25 4:34 ` Chen Gang
2013-09-26 5:58 ` Chen Gang
2013-09-26 6:30 ` Chen Gang
2013-09-26 13:15 ` Tejun Heo
2013-09-27 1:30 ` Chen Gang
2013-09-27 3:36 ` Tejun Heo
2013-09-27 7:16 ` Chen Gang
2013-09-27 11:53 ` Tejun Heo
2013-09-27 12:19 ` Chen Gang
2013-09-29 2:50 ` Chen Gang
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=52257248.9080508@asianux.com \
--to=gang.chen@asianux.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mtk.manpages@gmail.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