Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1111160ybt; Sun, 14 Jun 2020 10:43:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyK3SoVGmFVFdQ618RUCnHTyWbswgButUuEf6dnS2TwxHZRY4538xszOSCIKTa6Crf3DItN X-Received: by 2002:a17:906:481b:: with SMTP id w27mr21741183ejq.27.1592156623783; Sun, 14 Jun 2020 10:43:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592156623; cv=none; d=google.com; s=arc-20160816; b=PejXRkeNdd01eEmgE5RJ1+KT0xu01h8NrezXl/mHzuCxo7VXOVZkwjO7pD2rlBbaMM PlHyF2j+5xu8rZTbSspOm19OGejADd098oFq8GcsCFjdbeNGGNgAh4hlAoIK+Od79/0I 6IVxXvSoVk37lTJ9jaV7CLV6ecbK8ikCNaj55FGEOvxy5SZTvpWrtBC/TW5MXseRhf+D 6N/k1LAdPfbjjjjJgTABy8IU8p+/1TxW20SNQxQ1w2+QSS4ru2dar5jEz0QAT640XZe2 h2uL70/WaPR7I86AQ81HdrVOMzg3fHvh4ViKdlBJ65uedsZntbUjl9JZHKMaM7kWsEJN zsjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SB6Dz54LEXaI079WYzaT//jzQD8Xfx3RJc9hsvpoDXo=; b=L5EowgPDOZPTRzFrqrf00luxl2RNCcMcfjgrB7l0lIVUqPY9Z0P0pOKcEK7Or/b+FO xPH/foGyDEXGNosFIcVzprBKwFVUdkUFmHGzh4e9KY4ZU0TAm6cayhsR7hhHGDRyr0yk QAL+ut9wSgkP0Yk6BQ4qtxREhC71vAB/USFnTkNpnX3f/wvquO5fQjTiLxZzgIJzdNN3 JPX2D7Av1H56VPlpqbcCG/kB1Z8Xwq7zyE15231V9VmQ10HWRBj7+kUZKSNsdR2+eLfI QloU4dSOnZ+GoDEAQcgg8zfGjgoBK5zSSwoKsLBS/a8DEqlwg8lpHDiytbhKeuicqCdX AGyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MkfLYHg1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f4si6947472edm.426.2020.06.14.10.43.20; Sun, 14 Jun 2020 10:43:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MkfLYHg1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726999AbgFNRlc (ORCPT + 99 others); Sun, 14 Jun 2020 13:41:32 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:20614 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726513AbgFNRlc (ORCPT ); Sun, 14 Jun 2020 13:41:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592156491; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SB6Dz54LEXaI079WYzaT//jzQD8Xfx3RJc9hsvpoDXo=; b=MkfLYHg12HyNfjwOUcw1QcANdrK+L98J70mkb46o7s6Lgpr2+HT64YGEI6jcbXAySva3AW jZYk/nxAeP27vYYTDcpg4ifvjkTPi2sokIY4gpg/NVg+Uz1Y4HR8E31NMKm1a123rAi6NZ qNOTUfFNQ1fuh8QaOVhAhlb2CnXVQ/Q= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-333-BvZEzphEMly0GwbtUeBDAw-1; Sun, 14 Jun 2020 13:41:26 -0400 X-MC-Unique: BvZEzphEMly0GwbtUeBDAw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 922CA64AD2; Sun, 14 Jun 2020 17:41:25 +0000 (UTC) Received: from epycfail.redhat.com (unknown [10.36.110.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 42BDE1002396; Sun, 14 Jun 2020 17:41:23 +0000 (UTC) From: Stefano Brivio To: Andrew Morton , Andy Shevchenko Cc: Yury Norov , Rasmus Villemoes , Pablo Neira Ayuso , linux-kernel@vger.kernel.org Subject: [PATCH 1/2] bitmap: Fix bitmap_cut() for partial overlapping case Date: Sun, 14 Jun 2020 19:40:53 +0200 Message-Id: <003e38d4428cd6091ef00b5b03354f1bd7d9091e.1592155364.git.sbrivio@redhat.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Reported-by: Yury Norov Fixes: 2092767168f0 ("bitmap: Introduce bitmap_cut(): cut bits and shift remaining") Signed-off-by: Stefano Brivio --- 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