netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paul Moore <paul.moore@hp.com>
To: Roel Kluin <roel.kluin@gmail.com>,
	"David S. Miller" <davem@davemloft.net>
Cc: netdev@vger.kernel.org, Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH] cipso: subtraction on unsigned hdr_delta
Date: Wed, 4 Mar 2009 12:25:01 -0500	[thread overview]
Message-ID: <200903041225.01858.paul.moore@hp.com> (raw)
In-Reply-To: <49ADADEA.8090306@gmail.com>

On Tuesday 03 March 2009 05:23:38 pm Roel Kluin wrote:
> hdr_delta is unsigned, so take care not to subtract below 0.
>
> Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
> ---
> diff --git a/net/ipv4/cipso_ipv4.c b/net/ipv4/cipso_ipv4.c
> index 7bc9929..b1d862b 100644
> --- a/net/ipv4/cipso_ipv4.c
> +++ b/net/ipv4/cipso_ipv4.c
> @@ -1999,7 +1999,11 @@ void cipso_v4_sock_delattr(struct sock *sk)
>  				iter++;
>  		hdr_delta = opt->optlen;
>  		opt->optlen = (optlen_new + 3) & ~3;
> -		hdr_delta -= opt->optlen;
> +
> +		if (hdr_delta > opt->optlen)
> +			hdr_delta -= opt->optlen;
> +		else
> +			hdr_delta = 0;
>  	} else {
>  		/* only the cipso option was present on the socket so we can
>  		 * remove the entire option struct */

This patch isn't needed since I can't think of any sane reason why the 
hdr_delta subtraction would ever cause an error.  Similarly, I don't think 
David's concerns over the icsk_ext_hdr_len adjustment necessarily apply here 
either.  Let me try and explain, feel free to point out faults in my logic ...

This function, cipso_v4_sock_delattr(), is only used _to_ remove the CIPSO IP 
option from a socket, never to add it.  In the code snippet above we see the 
following three lines:

	hdr_delta = opt->optlen;
	opt->optlen = (optlen_new + 3) & ~3;
	hdr_delta -= opt->optlen;

The first line sets hdr_delta equal to length of the original IP option list 
(length includes the CIPSO option).  The second line calculates the new length 
of the IP option list (without the CIPSO option), complete with padding.  The 
third line subtracts the new option length from hdr_delta which is currently 
equal to original option length.  The only way that hdr_delta could ever be in 
danger of going negative would be if the removal of the CIPSO IP option caused 
the total IP option length to somehow increase; I just can't think how that 
would be possible.

-- 
paul moore
linux @ hp


      parent reply	other threads:[~2009-03-04 17:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-03 22:23 [PATCH] cipso: subtraction on unsigned hdr_delta Roel Kluin
2009-03-04  7:42 ` David Miller
2009-03-04 17:25 ` Paul Moore [this message]

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=200903041225.01858.paul.moore@hp.com \
    --to=paul.moore@hp.com \
    --cc=akpm@linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=roel.kluin@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;
as well as URLs for NNTP newsgroup(s).