Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp6016512ybc; Wed, 27 Nov 2019 13:27:46 -0800 (PST) X-Google-Smtp-Source: APXvYqyBpG/jd+p8sWeGZiA9hO9vzm68cBVp0dqHCmV71kNHlMQG8M9BobWWm+6kluVXFXKqn4nj X-Received: by 2002:a17:906:1ed7:: with SMTP id m23mr50712027ejj.326.1574890066115; Wed, 27 Nov 2019 13:27:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574890066; cv=none; d=google.com; s=arc-20160816; b=OiFZi3sBWqBZ6Do1J2ERztsmw+/wNnC6LqzCFJ4Elw1rx3HhLVnDUaTIV9XI0egTwp z16LwvwNLNmJ5ztdPsC7E8qo2rtQzybBegk1V8ZwiGu6CY+1Kv9QHWeAi6FLmo+nc3Fz hCfqdBZNsnHJAy5HA5Iawg8BpmAZIol4UsLyaca7KltX+r+XXCDI66Om+5dVq2I6LwiU 6sPrDKkIShsaS2EhT5zPao8ixypDjXCqXba4FzSqOdLaCKyZuiC8paPxh5v3DcSViY/N qaIhVZ02M0+3pAwImaYnQ3JdcwNdH/x4FtH1lkQSc0LcJqBzAcQme78X+JgLF5bQ46P1 3Vcg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1KD7fEfEhHMvcicQTSKn21gky95OzwCj0ll8ZiB5tE4=; b=BafqluqkGcVcZGeNrtDxvy+OWhPkWvm691riey4oN9+9HhN0PX1V2BBbIjpt5ilfCv iN9DmeE8mT6aWp1/R8SpDp6NqfWMqIPGnhA9dA/44RLOFve5n49rzcBcwkg1ZjViu3QO +bdijzRF0EMqnR4MLMkIFBe3IEbRP6QT6Q5CCyC4Yuwk4fNKUbTov/S+04p931gkh1Ei PZaoMr7Wqujm/k8KXQtAP33EbsEwcMal7wkGntbFj9emLZk//KbPsS0ZDqiAbKZJk3P9 OPCrM4SYDFK0gyAwr9M6oDGiR4PetwTE6mwNPIcPmwIefQa96YFZTFy4M8DVBQhEVP2z lvkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=z69TRZIa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l24si10730706edw.352.2019.11.27.13.27.23; Wed, 27 Nov 2019 13:27:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=z69TRZIa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731220AbfK0VCG (ORCPT + 99 others); Wed, 27 Nov 2019 16:02:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:54568 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727303AbfK0VCE (ORCPT ); Wed, 27 Nov 2019 16:02:04 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B512D20862; Wed, 27 Nov 2019 21:02:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574888523; bh=t6h2MdHKYMubMCHj2hQ1lpKMgX+mo2ybIpeMq9ud7/4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=z69TRZIaM/U+SCYjEfsm0iUCzXgAOsUK+2gJPxzzPZeVA3Mts4VKqCBbApjbdD0CZ e/sz+vRkogs6StMUyVpVsArA9zPtmlB932tAeWD7q3tekj2nDKHqdteiDreTO2Y0eI /0rC0gNDToWAJFZZWWCAHoEw20modlDE5aKNSVAE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Rasmus Villemoes , Andy Shevchenko , Yury Norov , Sudeep Holla , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 4.19 167/306] linux/bitmap.h: handle constant zero-size bitmaps correctly Date: Wed, 27 Nov 2019 21:30:17 +0100 Message-Id: <20191127203127.614192983@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203114.766709977@linuxfoundation.org> References: <20191127203114.766709977@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rasmus Villemoes [ Upstream commit 7275b097851a5e2e0dd4da039c7e96b59ac5314e ] The static inlines in bitmap.h do not handle a compile-time constant nbits==0 correctly (they dereference the passed src or dst pointers, despite only 0 words being valid to access). I had the 0-day buildbot chew on a patch [1] that would cause build failures for such cases without complaining, suggesting that we don't have any such users currently, at least for the 70 .config/arch combinations that was built. Should any turn up, make sure they use the out-of-line versions, which do handle nbits==0 correctly. This is of course not the most efficient, but it's much less churn than teaching all the static inlines an "if (zero_const_nbits())", and since we don't have any current instances, this doesn't affect existing code at all. [1] lkml.kernel.org/r/20180815085539.27485-1-linux@rasmusvillemoes.dk Link: http://lkml.kernel.org/r/20180818131623.8755-3-linux@rasmusvillemoes.dk Signed-off-by: Rasmus Villemoes Reviewed-by: Andy Shevchenko Cc: Yury Norov Cc: Rasmus Villemoes Cc: Sudeep Holla Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- include/linux/bitmap.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index acf5e8df3504f..a9805bacbd7ca 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -204,8 +204,13 @@ extern int bitmap_print_to_pagebuf(bool list, char *buf, #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1))) #define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1))) +/* + * The static inlines below do not handle constant nbits==0 correctly, + * so make such users (should any ever turn up) call the out-of-line + * versions. + */ #define small_const_nbits(nbits) \ - (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG) + (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG && (nbits) > 0) static inline void bitmap_zero(unsigned long *dst, unsigned int nbits) { -- 2.20.1