public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
From: Sunil Mushran <sunil.mushran@oracle.com>
To: ocfs2-devel@oss.oracle.com
Subject: Re: [patch] ocfs2: tighten up strlen() checking
Date: Mon, 12 Jul 2010 16:49:59 +0000	[thread overview]
Message-ID: <4C3B47B7.9040108@oracle.com> (raw)
In-Reply-To: <20100712113006.GA2393@laptop.jp.oracle.com>

So o2dlm expects a null terminated domain name. The original
patch is good as it adds the check in o2dlm only.

For userspace, we allow non-null terminating group (domain) name.
That remains unchanged.

On 07/12/2010 04:30 AM, Wengang Wang wrote:
> Hi Dan,
>
> I think O2NM_MAX_NAME_LEN is the max valid length of the domain name.
> Regarding your patch, it changed to be that a domain name with length
> O2NM_MAX_NAME_LEN (NULL character not included) is not permitted.
>
> Though that check seems useless for current calls, we'd better keep it.
>
> Checking the structure,
>
>   99 struct ocfs2_cluster_connection {
> 100         char cc_name[GROUP_NAME_MAX];
> 101         int cc_namelen;
>
> cc_name is not a NULL tailed string. the cc_namelen specifies the length of it.
> There does is misuse of cc_name, such as
>
>
>     7    832  fs/ocfs2/stack_user.c<<user_cluster_connect>>
>               rc = dlm_new_lockspace(conn->cc_name, strlen(conn->cc_name),
>
>     5    308  fs/ocfs2/stack_o2cb.c<<o2cb_cluster_connect>>
>               dlm = dlm_register_domain(conn->cc_name, dlm_key,&fs_version);
>
> Also, the uuid shouldn't be treated as NULL tailed string.
> 142 struct ocfs2_control_message_down {
> 143         char    tag[OCFS2_CONTROL_MESSAGE_OP_LEN];
> 144         char    space1;
> 145         char    uuid[OCFS2_TEXT_UUID_LEN];
> 146         char    space2;
>
> thus,
> the calling of
> fs/ocfs2/stack_user.c:474:      ocfs2_control_send_down(msg->uuid, nodenum);
>     ->ocfs2_connection_find(uuid)
> 	->size_t len = strlen(name);
>
> is suspectable.
>
> Could you please make patch for that instead?
>
> regards,
> wengang.
>
> On 10-07-10 16:33, Dan Carpenter wrote:
>    
>> This function is only called from one place and it's like this:
>> 	dlm_register_domain(conn->cc_name, dlm_key,&fs_version);
>>
>> The "conn->cc_name" is 64 characters long.  If strlen(conn->cc_name)
>> were equal to O2NM_MAX_NAME_LEN (64) that would be a bug because
>> strlen() doesn't count the NULL character.
>>
>> In fact, if you look how O2NM_MAX_NAME_LEN is used, it mostly describes
>> 64 character buffers.  The only exception is nd_name from struct
>> o2nm_node.
>>
>> Anyway I looked into it and in this case the domain string comes from
>> osb->uuid_str in ocfs2_setup_osb_uuid().  That's 32 characters and NULL
>> which easily fits into O2NM_MAX_NAME_LEN.  This patch doesn't change how
>> the code works, but I think it makes the code a little cleaner.
>>
>> Signed-off-by: Dan Carpenter<error27@gmail.com>
>> ---
>> Or we could get rid of check entirely.
>>
>> diff --git a/fs/ocfs2/dlm/dlmdomain.c b/fs/ocfs2/dlm/dlmdomain.c
>> index 6b5a492..084b051 100644
>> --- a/fs/ocfs2/dlm/dlmdomain.c
>> +++ b/fs/ocfs2/dlm/dlmdomain.c
>> @@ -1671,7 +1671,7 @@ struct dlm_ctxt * dlm_register_domain(const char *domain,
>>   	struct dlm_ctxt *dlm = NULL;
>>   	struct dlm_ctxt *new_ctxt = NULL;
>>
>> -	if (strlen(domain)>  O2NM_MAX_NAME_LEN) {
>> +	if (strlen(domain)>= O2NM_MAX_NAME_LEN) {
>>   		ret = -ENAMETOOLONG;
>>   		mlog(ML_ERROR, "domain name length too long\n");
>>   		goto leave;
>>      


  parent reply	other threads:[~2010-07-12 16:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-10 14:33 [patch] ocfs2: tighten up strlen() checking Dan Carpenter
2010-07-12 11:30 ` Wengang Wang
2010-07-12 13:39   ` Dan Carpenter
2010-07-12 14:31     ` Wengang Wang
2010-07-12 16:49   ` Sunil Mushran [this message]
2010-07-12 16:46 ` Sunil Mushran
2010-07-12 18:33 ` Joel Becker

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=4C3B47B7.9040108@oracle.com \
    --to=sunil.mushran@oracle.com \
    --cc=ocfs2-devel@oss.oracle.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