public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Stefano Brivio <sbrivio@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Yury Norov <yury.norov@gmail.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Pablo Neira Ayuso <pablo@netfilter.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] bitmap: Fix bitmap_cut() for partial overlapping case
Date: Mon, 15 Jun 2020 12:42:38 +0300	[thread overview]
Message-ID: <20200615094238.GR2428291@smile.fi.intel.com> (raw)
In-Reply-To: <003e38d4428cd6091ef00b5b03354f1bd7d9091e.1592155364.git.sbrivio@redhat.com>

On Sun, Jun 14, 2020 at 07:40:53PM +0200, Stefano Brivio wrote:
> Yury Norov reports that bitmap_cut() will not produce the right outcome
> if src and dst partially overlap, with src pointing at some location
> after dst, because the memmove() affects src before we store the bits
> that we need to keep, that is, the bits preceding the cut -- as long as
> we the beginning of the cut is not aligned to a long.
> 
> Fix this by storing those bits before the memmove().
> 
> Note that this is just a theoretical concern so far, as the only user
> of this function, pipapo_drop() from the nftables set back-end
> implemented in net/netfilter/nft_set_pipapo.c, always supplies entirely
> overlapping src and dst.

LGTM as long as test cases are passed,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

> Reported-by: Yury Norov <yury.norov@gmail.com>
> Fixes: 2092767168f0 ("bitmap: Introduce bitmap_cut(): cut bits and shift remaining")
> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
> ---
> v2: No changes
> 
>  lib/bitmap.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/bitmap.c b/lib/bitmap.c
> index 89260aa342d6..c5712e8f4c38 100644
> --- a/lib/bitmap.c
> +++ b/lib/bitmap.c
> @@ -211,13 +211,13 @@ void bitmap_cut(unsigned long *dst, const unsigned long *src,
>  	unsigned long keep = 0, carry;
>  	int i;
>  
> -	memmove(dst, src, len * sizeof(*dst));
> -
>  	if (first % BITS_PER_LONG) {
>  		keep = src[first / BITS_PER_LONG] &
>  		       (~0UL >> (BITS_PER_LONG - first % BITS_PER_LONG));
>  	}
>  
> +	memmove(dst, src, len * sizeof(*dst));
> +
>  	while (cut--) {
>  		for (i = first / BITS_PER_LONG; i < len; i++) {
>  			if (i < len - 1)
> -- 
> 2.27.0
> 

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2020-06-15  9:42 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-14 17:40 [PATCH 0/2] lib: Fix bitmap_cut() for overlaps, add test Stefano Brivio
2020-06-14 17:40 ` [PATCH 1/2] bitmap: Fix bitmap_cut() for partial overlapping case Stefano Brivio
2020-06-15  9:42   ` Andy Shevchenko [this message]
2020-06-14 17:40 ` [PATCH 2/2] bitmap: Add test for bitmap_cut() Stefano Brivio
2020-06-15  9:41   ` Andy Shevchenko
2020-06-15  9:46     ` Andy Shevchenko
2020-06-15 11:08       ` Stefano Brivio
2020-06-15 11:43         ` Andy Shevchenko
2020-06-15 13:16           ` Stefano Brivio
2020-06-15 12:04       ` Alexander Gordeev

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=20200615094238.GR2428291@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=pablo@netfilter.org \
    --cc=sbrivio@redhat.com \
    --cc=yury.norov@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