All of lore.kernel.org
 help / color / mirror / Atom feed
From: walter harms <wharms@bfs.de>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Karsten Keil <isdn@linux-pingi.de>,
	netdev@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [patch] isdn: make sure strings are null terminated
Date: Thu, 24 Nov 2011 12:21:42 +0000	[thread overview]
Message-ID: <4ECE36D6.7060503@bfs.de> (raw)
In-Reply-To: <20111124113456.GI3258@mwanda>



Am 24.11.2011 12:34, schrieb Dan Carpenter:
> On Wed, Nov 23, 2011 at 09:25:56AM +0100, walter harms wrote:
>>
>>
>> Am 23.11.2011 07:42, schrieb Dan Carpenter:
>>> These strings come from the user.  We strcpy() them inside
>>> cf_command() so we should check that they are NULL terminated and
>>> return an error if not.
>>>
>>> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>>>
>>> diff --git a/drivers/isdn/divert/divert_procfs.c b/drivers/isdn/divert/divert_procfs.c
>>> index 33ec9e4..0c16687 100644
>>> --- a/drivers/isdn/divert/divert_procfs.c
>>> +++ b/drivers/isdn/divert/divert_procfs.c
>>> @@ -242,6 +242,10 @@ static int isdn_divert_ioctl_unlocked(struct file *file, uint cmd, ulong arg)
>>>  		case IIOCDOCFINT:
>>>  			if (!divert_if.drv_to_name(dioctl.cf_ctrl.drvid))
>>>  				return (-EINVAL);	/* invalid driver */
>>> +			if (strlen(dioctl.cf_ctrl.msn) >= sizeof(dioctl.cf_ctrl.msn))
>>> +				return -EINVAL;
>>> +			if (strlen(dioctl.cf_ctrl.fwd_nr) >= sizeof(dioctl.cf_ctrl.fwd_nr))
>>> +				return -EINVAL;
>>
>> forcing the last field to be zero seems more easy.
>> dioctl.cf_ctrl.fwd_nr[sizeof(dioctl.cf_ctrl.fwd_nr))-1]=0;
>>
> 
> That's a valid option to use, but I'd prefer to return an error code
> here because that's what we do on the line before.  Passing a too
> long string is clearly invalid.
> 

the line before has the same problem, of cause.

So far i see you do not get a string, you get a structure. An it will hard
to validate the element is a useful string. I thing my (sledgehammer) method
is ok here because you make sure that all later calls (strcmp,strcpy) will succeed.
If someone supplies a bad string the later calls will catch by failing to identify
and return a proper code from there (at least i hope so).

re,
 wh




WARNING: multiple messages have this Message-ID (diff)
From: walter harms <wharms@bfs.de>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Karsten Keil <isdn@linux-pingi.de>,
	netdev@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [patch] isdn: make sure strings are null terminated
Date: Thu, 24 Nov 2011 13:21:42 +0100	[thread overview]
Message-ID: <4ECE36D6.7060503@bfs.de> (raw)
In-Reply-To: <20111124113456.GI3258@mwanda>



Am 24.11.2011 12:34, schrieb Dan Carpenter:
> On Wed, Nov 23, 2011 at 09:25:56AM +0100, walter harms wrote:
>>
>>
>> Am 23.11.2011 07:42, schrieb Dan Carpenter:
>>> These strings come from the user.  We strcpy() them inside
>>> cf_command() so we should check that they are NULL terminated and
>>> return an error if not.
>>>
>>> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>>>
>>> diff --git a/drivers/isdn/divert/divert_procfs.c b/drivers/isdn/divert/divert_procfs.c
>>> index 33ec9e4..0c16687 100644
>>> --- a/drivers/isdn/divert/divert_procfs.c
>>> +++ b/drivers/isdn/divert/divert_procfs.c
>>> @@ -242,6 +242,10 @@ static int isdn_divert_ioctl_unlocked(struct file *file, uint cmd, ulong arg)
>>>  		case IIOCDOCFINT:
>>>  			if (!divert_if.drv_to_name(dioctl.cf_ctrl.drvid))
>>>  				return (-EINVAL);	/* invalid driver */
>>> +			if (strlen(dioctl.cf_ctrl.msn) >= sizeof(dioctl.cf_ctrl.msn))
>>> +				return -EINVAL;
>>> +			if (strlen(dioctl.cf_ctrl.fwd_nr) >= sizeof(dioctl.cf_ctrl.fwd_nr))
>>> +				return -EINVAL;
>>
>> forcing the last field to be zero seems more easy.
>> dioctl.cf_ctrl.fwd_nr[sizeof(dioctl.cf_ctrl.fwd_nr))-1]=0;
>>
> 
> That's a valid option to use, but I'd prefer to return an error code
> here because that's what we do on the line before.  Passing a too
> long string is clearly invalid.
> 

the line before has the same problem, of cause.

So far i see you do not get a string, you get a structure. An it will hard
to validate the element is a useful string. I thing my (sledgehammer) method
is ok here because you make sure that all later calls (strcmp,strcpy) will succeed.
If someone supplies a bad string the later calls will catch by failing to identify
and return a proper code from there (at least i hope so).

re,
 wh

  reply	other threads:[~2011-11-24 12:21 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-23  6:42 [patch] isdn: make sure strings are null terminated Dan Carpenter
2011-11-23  6:42 ` Dan Carpenter
2011-11-23  7:03 ` Eric Dumazet
2011-11-23  7:03   ` Eric Dumazet
2011-11-23  7:16   ` Dan Carpenter
2011-11-23  7:16     ` Dan Carpenter
2011-11-24 12:41   ` [patch v2] " Dan Carpenter
2011-11-24 12:41     ` Dan Carpenter
2011-11-29 23:40     ` David Miller
2011-11-29 23:40       ` David Miller
2011-11-23  8:25 ` [patch] " walter harms
2011-11-23  8:25   ` walter harms
2011-11-24 11:34   ` Dan Carpenter
2011-11-24 11:34     ` Dan Carpenter
2011-11-24 12:21     ` walter harms [this message]
2011-11-24 12:21       ` walter harms
2011-11-24 12:30       ` David Laight
2011-11-24 12:30         ` David Laight
2011-11-24 13:17       ` Karsten Keil
2011-11-24 13:17         ` Karsten Keil

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=4ECE36D6.7060503@bfs.de \
    --to=wharms@bfs.de \
    --cc=dan.carpenter@oracle.com \
    --cc=isdn@linux-pingi.de \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.