mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Yury Norov <yury.norov@gmail.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Pablo Neira Ayuso <pablo@netfilter.org>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] lib: Fix bitmap_cut() for partial overlapping case
Date: Mon,  8 Jun 2020 11:13:28 +0200	[thread overview]
Message-ID: <003e38d4428cd6091ef00b5b03354f1bd7d9091e.1591606281.git.sbrivio@redhat.com> (raw)
In-Reply-To: <cover.1591606281.git.sbrivio@redhat.com>

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

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


  reply	other threads:[~2020-06-08  9:13 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-08  9:13 [PATCH 0/2] lib: Fix bitmap_cut() for overlaps, add test Stefano Brivio
2020-06-08  9:13 ` Stefano Brivio [this message]
2020-06-08  9:13 ` [PATCH 2/2] lib: Add test for bitmap_cut() Stefano Brivio
2020-06-08 10:12   ` Andy Shevchenko
2020-06-08 10:27     ` Stefano Brivio
2020-06-08 11:31       ` Andy Shevchenko
2020-06-08 11:51         ` Stefano Brivio
2020-06-10  7:42   ` [lib] 0a1d3d4a3c: Kernel_panic-not_syncing:stack-protector:Kernel_stack_is_corrupted_in:test_bitmap_init kernel test robot
2020-06-08 10:13 ` [PATCH 0/2] lib: Fix bitmap_cut() for overlaps, add test Andy Shevchenko

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=003e38d4428cd6091ef00b5b03354f1bd7d9091e.1591606281.git.sbrivio@redhat.com \
    --to=sbrivio@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=pablo@netfilter.org \
    --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

all inboxes | Powered by JetHome®