netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] net: ndisc.c: reduce size of __ndisc_fill_addr_option()
@ 2017-05-26 22:00 yuan linyu
  2017-05-30  3:30 ` David Miller
  0 siblings, 1 reply; 12+ messages in thread
From: yuan linyu @ 2017-05-26 22:00 UTC (permalink / raw)
  To: netdev; +Cc: David S . Miller, Joe Perches, David Ahern, yuan linyu

From: yuan linyu <Linyu.Yuan@alcatel-sbell.com.cn>

Signed-off-by: yuan linyu <Linyu.Yuan@alcatel-sbell.com.cn>
---
 net/ipv6/ndisc.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c
index d310dc4..414e929 100644
--- a/net/ipv6/ndisc.c
+++ b/net/ipv6/ndisc.c
@@ -148,17 +148,18 @@ void __ndisc_fill_addr_option(struct sk_buff *skb, int type, void *data,
 
 	opt[0] = type;
 	opt[1] = space>>3;
+	opt   += 2;
+	space -= 2;
 
-	memset(opt + 2, 0, pad);
+	memset(opt, 0, pad);
 	opt   += pad;
 	space -= pad;
 
-	memcpy(opt+2, data, data_len);
-	data_len += 2;
+	memcpy(opt, data, data_len);
 	opt += data_len;
 	space -= data_len;
-	if (space > 0)
-		memset(opt, 0, space);
+
+	memset(opt, 0, space);
 }
 EXPORT_SYMBOL_GPL(__ndisc_fill_addr_option);
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH net-next] net: ndisc.c: reduce size of __ndisc_fill_addr_option()
@ 2017-05-27 15:15 Alexey Dobriyan
  2017-05-30  3:31 ` David Miller
  0 siblings, 1 reply; 12+ messages in thread
From: Alexey Dobriyan @ 2017-05-27 15:15 UTC (permalink / raw)
  To: Linyu.Yuan; +Cc: netdev, davem

> --- a/net/ipv6/ndisc.c
> +++ b/net/ipv6/ndisc.c
> @@ -148,17 +148,18 @@ void __ndisc_fill_addr_option(struct sk_buff *skb, int type, void *data,

>  	space -= data_len;
> -	if (space > 0)
> -		memset(opt, 0, space);
> +
> +	memset(opt, 0, space);

This can't be right.

And what size are you reducing?

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH net-next] net: ndisc.c: reduce size of __ndisc_fill_addr_option()
  2017-05-26 22:00 [PATCH net-next] net: ndisc.c: reduce size of __ndisc_fill_addr_option() yuan linyu
@ 2017-05-30  3:30 ` David Miller
  2017-05-30  3:41   ` Joe Perches
  0 siblings, 1 reply; 12+ messages in thread
From: David Miller @ 2017-05-30  3:30 UTC (permalink / raw)
  To: cugyly; +Cc: netdev, joe, dsahern, Linyu.Yuan

From: yuan linyu <cugyly@163.com>
Date: Sat, 27 May 2017 06:00:52 +0800

> From: yuan linyu <Linyu.Yuan@alcatel-sbell.com.cn>
> 
> Signed-off-by: yuan linyu <Linyu.Yuan@alcatel-sbell.com.cn>

Applied, thanks.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH net-next] net: ndisc.c: reduce size of __ndisc_fill_addr_option()
  2017-05-27 15:15 Alexey Dobriyan
@ 2017-05-30  3:31 ` David Miller
  2017-05-30  4:24   ` Joe Perches
  0 siblings, 1 reply; 12+ messages in thread
From: David Miller @ 2017-05-30  3:31 UTC (permalink / raw)
  To: adobriyan; +Cc: Linyu.Yuan, netdev

From: Alexey Dobriyan <adobriyan@gmail.com>
Date: Sat, 27 May 2017 18:15:14 +0300

>> --- a/net/ipv6/ndisc.c
>> +++ b/net/ipv6/ndisc.c
>> @@ -148,17 +148,18 @@ void __ndisc_fill_addr_option(struct sk_buff *skb, int type, void *data,
> 
>>  	space -= data_len;
>> -	if (space > 0)
>> -		memset(opt, 0, space);
>> +
>> +	memset(opt, 0, space);
> 
> This can't be right.
> 
> And what size are you reducing?

It is right, space equals the same thing it would have equaled
before his changes, and a memset() of zero length will do the
right thing.

Finally, if space can be negative here, we have real problems.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH net-next] net: ndisc.c: reduce size of __ndisc_fill_addr_option()
  2017-05-30  3:30 ` David Miller
@ 2017-05-30  3:41   ` Joe Perches
  2017-05-30  3:42     ` David Ahern
  2017-05-31  0:06     ` YUAN Linyu
  0 siblings, 2 replies; 12+ messages in thread
From: Joe Perches @ 2017-05-30  3:41 UTC (permalink / raw)
  To: David Miller, cugyly; +Cc: netdev, dsahern, Linyu.Yuan

On Mon, 2017-05-29 at 23:30 -0400, David Miller wrote:
> From: yuan linyu <cugyly@163.com>
> Date: Sat, 27 May 2017 06:00:52 +0800
> 
> > From: yuan linyu <Linyu.Yuan@alcatel-sbell.com.cn>
> > 
> > Signed-off-by: yuan linyu <Linyu.Yuan@alcatel-sbell.com.cn>
> 
> Applied, thanks.

OK, but is it really safe though?

Could "space" (an int) ever be negative after
subtracting "pad" and "data_len"?

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH net-next] net: ndisc.c: reduce size of __ndisc_fill_addr_option()
  2017-05-30  3:41   ` Joe Perches
@ 2017-05-30  3:42     ` David Ahern
  2017-05-31  0:07       ` YUAN Linyu
  2017-05-31  0:29       ` YUAN Linyu
  2017-05-31  0:06     ` YUAN Linyu
  1 sibling, 2 replies; 12+ messages in thread
From: David Ahern @ 2017-05-30  3:42 UTC (permalink / raw)
  To: Joe Perches, David Miller, cugyly; +Cc: netdev, Linyu.Yuan

On 5/29/17 9:41 PM, Joe Perches wrote:
> On Mon, 2017-05-29 at 23:30 -0400, David Miller wrote:
>> From: yuan linyu <cugyly@163.com>
>> Date: Sat, 27 May 2017 06:00:52 +0800
>>
>>> From: yuan linyu <Linyu.Yuan@alcatel-sbell.com.cn>
>>>
>>> Signed-off-by: yuan linyu <Linyu.Yuan@alcatel-sbell.com.cn>
>> Applied, thanks.
> OK, but is it really safe though?
> 
> Could "space" (an int) ever be negative after
> subtracting "pad" and "data_len"?
> 

that function should be converted to skb_put_zero once it hits net-next.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH net-next] net: ndisc.c: reduce size of __ndisc_fill_addr_option()
  2017-05-30  3:31 ` David Miller
@ 2017-05-30  4:24   ` Joe Perches
  0 siblings, 0 replies; 12+ messages in thread
From: Joe Perches @ 2017-05-30  4:24 UTC (permalink / raw)
  To: David Miller, adobriyan; +Cc: Linyu.Yuan, netdev

On Mon, 2017-05-29 at 23:31 -0400, David Miller wrote:
> From: Alexey Dobriyan <adobriyan@gmail.com>
> Date: Sat, 27 May 2017 18:15:14 +0300
> 
> >> --- a/net/ipv6/ndisc.c
> >> +++ b/net/ipv6/ndisc.c
> >> @@ -148,17 +148,18 @@ void __ndisc_fill_addr_option(struct sk_buff *skb, int type, void *data,
> > 
> >>      space -= data_len;
> >> -    if (space > 0)
> >> -            memset(opt, 0, space);
> >> +
> >> +    memset(opt, 0, space);
> > 
> > This can't be right.
> > 
> > And what size are you reducing?
> 
> It is right, space equals the same thing it would have equaled
> before his changes, and a memset() of zero length will do the
> right thing.
> 
> Finally, if space can be negative here, we have real problems.

__ndisc_fill_addr_option is exported so yeah.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [PATCH net-next] net: ndisc.c: reduce size of __ndisc_fill_addr_option()
  2017-05-30  3:41   ` Joe Perches
  2017-05-30  3:42     ` David Ahern
@ 2017-05-31  0:06     ` YUAN Linyu
  1 sibling, 0 replies; 12+ messages in thread
From: YUAN Linyu @ 2017-05-31  0:06 UTC (permalink / raw)
  To: Joe Perches, David Miller, cugyly@163.com
  Cc: netdev@vger.kernel.org, dsahern@gmail.com

Hi joe,

> -----Original Message-----
> From: netdev-owner@vger.kernel.org [mailto:netdev-owner@vger.kernel.org]
> On Behalf Of Joe Perches
> Sent: Tuesday, May 30, 2017 11:41 AM
> To: David Miller; cugyly@163.com
> Cc: netdev@vger.kernel.org; dsahern@gmail.com; YUAN Linyu
> Subject: Re: [PATCH net-next] net: ndisc.c: reduce size of
> __ndisc_fill_addr_option()
> 
> On Mon, 2017-05-29 at 23:30 -0400, David Miller wrote:
> > From: yuan linyu <cugyly@163.com>
> > Date: Sat, 27 May 2017 06:00:52 +0800
> >
> > > From: yuan linyu <Linyu.Yuan@alcatel-sbell.com.cn>
> > >
> > > Signed-off-by: yuan linyu <Linyu.Yuan@alcatel-sbell.com.cn>
> >
> > Applied, thanks.
> 
> OK, but is it really safe though?
> 
> Could "space" (an int) ever be negative after
> subtracting "pad" and "data_len"?
It's safe, check
int space = __ndisc_opt_addr_space(data_len, pad);
space is maximum aligned value.
And I check current pad, the maximum value is 2.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [PATCH net-next] net: ndisc.c: reduce size of __ndisc_fill_addr_option()
  2017-05-30  3:42     ` David Ahern
@ 2017-05-31  0:07       ` YUAN Linyu
  2017-05-31  0:29       ` YUAN Linyu
  1 sibling, 0 replies; 12+ messages in thread
From: YUAN Linyu @ 2017-05-31  0:07 UTC (permalink / raw)
  To: David Ahern, Joe Perches, David Miller, cugyly@163.com
  Cc: netdev@vger.kernel.org



> -----Original Message-----
> From: David Ahern [mailto:dsahern@gmail.com]
> Sent: Tuesday, May 30, 2017 11:42 AM
> To: Joe Perches; David Miller; cugyly@163.com
> Cc: netdev@vger.kernel.org; YUAN Linyu
> Subject: Re: [PATCH net-next] net: ndisc.c: reduce size of
> __ndisc_fill_addr_option()
> 
> On 5/29/17 9:41 PM, Joe Perches wrote:
> > On Mon, 2017-05-29 at 23:30 -0400, David Miller wrote:
> >> From: yuan linyu <cugyly@163.com>
> >> Date: Sat, 27 May 2017 06:00:52 +0800
> >>
> >>> From: yuan linyu <Linyu.Yuan@alcatel-sbell.com.cn>
> >>>
> >>> Signed-off-by: yuan linyu <Linyu.Yuan@alcatel-sbell.com.cn>
> >> Applied, thanks.
> > OK, but is it really safe though?
> >
> > Could "space" (an int) ever be negative after
> > subtracting "pad" and "data_len"?
> >
> 
> that function should be converted to skb_put_zero once it hits net-next.
I will check it

^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [PATCH net-next] net: ndisc.c: reduce size of __ndisc_fill_addr_option()
  2017-05-30  3:42     ` David Ahern
  2017-05-31  0:07       ` YUAN Linyu
@ 2017-05-31  0:29       ` YUAN Linyu
  2017-05-31  0:39         ` David Ahern
  1 sibling, 1 reply; 12+ messages in thread
From: YUAN Linyu @ 2017-05-31  0:29 UTC (permalink / raw)
  To: David Ahern, Joe Perches, David Miller, cugyly@163.com
  Cc: netdev@vger.kernel.org

> > -----Original Message-----
> > From: David Ahern [mailto:dsahern@gmail.com]
> > Sent: Tuesday, May 30, 2017 11:42 AM
> > To: Joe Perches; David Miller; cugyly@163.com
> > Cc: netdev@vger.kernel.org; YUAN Linyu
> > Subject: Re: [PATCH net-next] net: ndisc.c: reduce size of
> > __ndisc_fill_addr_option()
> >
> > On 5/29/17 9:41 PM, Joe Perches wrote:
> > > On Mon, 2017-05-29 at 23:30 -0400, David Miller wrote:
> > >> From: yuan linyu <cugyly@163.com>
> > >> Date: Sat, 27 May 2017 06:00:52 +0800
> > >>
> > >>> From: yuan linyu <Linyu.Yuan@alcatel-sbell.com.cn>
> > >>>
> > >>> Signed-off-by: yuan linyu <Linyu.Yuan@alcatel-sbell.com.cn>
> > >> Applied, thanks.
> > > OK, but is it really safe though?
> > >
> > > Could "space" (an int) ever be negative after
> > > subtracting "pad" and "data_len"?
> > >
> >
> > that function should be converted to skb_put_zero once it hits net-next.
> I will check it
I can't find skb_put_zero

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH net-next] net: ndisc.c: reduce size of __ndisc_fill_addr_option()
  2017-05-31  0:29       ` YUAN Linyu
@ 2017-05-31  0:39         ` David Ahern
  2017-05-31  1:00           ` YUAN Linyu
  0 siblings, 1 reply; 12+ messages in thread
From: David Ahern @ 2017-05-31  0:39 UTC (permalink / raw)
  To: YUAN Linyu, David Ahern, Joe Perches, David Miller,
	cugyly@163.com
  Cc: netdev@vger.kernel.org

On 5/30/17 6:29 PM, YUAN Linyu wrote:
>>> that function should be converted to skb_put_zero once it hits net-next.
>> I will check it
> I can't find skb_put_zero

I believe the decision was to put it in Johannes' tree and it will make
its way to DaveM's tree. Give some time.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [PATCH net-next] net: ndisc.c: reduce size of __ndisc_fill_addr_option()
  2017-05-31  0:39         ` David Ahern
@ 2017-05-31  1:00           ` YUAN Linyu
  0 siblings, 0 replies; 12+ messages in thread
From: YUAN Linyu @ 2017-05-31  1:00 UTC (permalink / raw)
  To: David Ahern, Joe Perches, David Miller, cugyly@163.com
  Cc: netdev@vger.kernel.org

Ok, I will send v2 later

> -----Original Message-----
> From: David Ahern [mailto:dsahern@gmail.com]
> Sent: Wednesday, May 31, 2017 8:40 AM
> To: YUAN Linyu; David Ahern; Joe Perches; David Miller; cugyly@163.com
> Cc: netdev@vger.kernel.org
> Subject: Re: [PATCH net-next] net: ndisc.c: reduce size of
> __ndisc_fill_addr_option()
> 
> On 5/30/17 6:29 PM, YUAN Linyu wrote:
> >>> that function should be converted to skb_put_zero once it hits net-next.
> >> I will check it
> > I can't find skb_put_zero
> 
> I believe the decision was to put it in Johannes' tree and it will make
> its way to DaveM's tree. Give some time.

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2017-05-31  1:00 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-26 22:00 [PATCH net-next] net: ndisc.c: reduce size of __ndisc_fill_addr_option() yuan linyu
2017-05-30  3:30 ` David Miller
2017-05-30  3:41   ` Joe Perches
2017-05-30  3:42     ` David Ahern
2017-05-31  0:07       ` YUAN Linyu
2017-05-31  0:29       ` YUAN Linyu
2017-05-31  0:39         ` David Ahern
2017-05-31  1:00           ` YUAN Linyu
2017-05-31  0:06     ` YUAN Linyu
  -- strict thread matches above, loose matches on Subject: below --
2017-05-27 15:15 Alexey Dobriyan
2017-05-30  3:31 ` David Miller
2017-05-30  4:24   ` Joe Perches

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).