Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2652225pxa; Mon, 17 Aug 2020 15:34:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwb6GB7TnE5PVjljDWU3zHEILTidod68BwuWr/nqJaRHrFPM2ywzSDa6Hr2kUaCIbja2LgU X-Received: by 2002:a17:906:86c9:: with SMTP id j9mr16959336ejy.5.1597703647502; Mon, 17 Aug 2020 15:34:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597703647; cv=none; d=google.com; s=arc-20160816; b=uXgFcKhgHW1C0/U1SnnDM6aygzFzwmNEn4vP3Angr6Pw4y3fFYppKmScl/YucOBeoM V33USko1SyNGyPIGkaVWXtxQlDlFeJVOMKbthjeWs96Fdc8hY+gfj4M7tCQJ0YqholKP zW6pvButOukxUKXf416EAqh6yV/rd+7miCkpRQt5Gr0U/iS1EgRRzb5LE/ddeZxwYEbR c+77X9rFE0SO+PYv9nB95zAMzHqKwD4VhuAH+xOsrt5Fj1DYlbiYv6FGni24Ran0cHH9 MOhwFImJsg3Ho6kj0k6BAPJ58Kf43iwUCTwKHxhwHugFYnP893odQhS67HtoFbJ9CsGu vasw== 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=K5Ochwv+l23gAYSzwRA9ajHGws8PuDVnSqknJW4uYPE=; b=gpD//+1AS6VJ1t/Pe1ku1BBGgP4YwpEOmX70U1KFzNVxSlBYJKnjzpsAmDCF8Yahok YHgmokCPsZm8J3HyKbky52w4J1yy7vXBIhYlPvHoQMc8uonkiccT2ud5zAEUgLOUrmg4 79zD4qA6Ixz+dIg12I4OZBywglTe9hyFm9IrQNTyvzTbwk8uqTrdbfKHs+Vdi5QYozEt gnJucHr86iDjORLiKjC0OFJ2EUT1C7g0TRzoeM0WQ0/5Qu+gQ7anFw3ILPMBkwLxTC+E hV26Ah666XyH0WSVl+Axlo5P2dCRDuR9jG6PC4VTAfLSdnO2j9G3hd7kPI/l9WPl6HP3 ouFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ibXO9k88; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p62si13073504edb.9.2020.08.17.15.33.39; Mon, 17 Aug 2020 15:34:07 -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=@kernel.org header.s=default header.b=ibXO9k88; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389346AbgHQRIb (ORCPT + 99 others); Mon, 17 Aug 2020 13:08:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:37410 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388575AbgHQQKx (ORCPT ); Mon, 17 Aug 2020 12:10:53 -0400 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 F0DB320729; Mon, 17 Aug 2020 16:10:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597680652; bh=CAZDTOlSXeiXvjXUcKkxqT5P8FHgyvW4xuTDWxyLWxQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ibXO9k88otT/QRZi3JSXk1VJhWCNwGBZsiRozy2I+KKMAsGKV4YQ0o2e95PJPTuoY G3yMMsCtDjuN2I5WxZrBtc3YDPbdXPuXf45JvYh7+V7ILoFwjTVquzIxL6g1NJPdCn kNtkUNASdUv8XLHci2M8VvXAvjorndDICamLUMVg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Masahiro Yamada , Jakub Kicinski , Nick Desaulniers , "David S. Miller" , Sami Tolvanen Subject: [PATCH 5.4 261/270] bitfield.h: dont compile-time validate _val in FIELD_FIT Date: Mon, 17 Aug 2020 17:17:42 +0200 Message-Id: <20200817143808.820042758@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143755.807583758@linuxfoundation.org> References: <20200817143755.807583758@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: Jakub Kicinski commit 444da3f52407d74c9aa12187ac6b01f76ee47d62 upstream. When ur_load_imm_any() is inlined into jeq_imm(), it's possible for the compiler to deduce a case where _val can only have the value of -1 at compile time. Specifically, /* struct bpf_insn: _s32 imm */ u64 imm = insn->imm; /* sign extend */ if (imm >> 32) { /* non-zero only if insn->imm is negative */ /* inlined from ur_load_imm_any */ u32 __imm = imm >> 32; /* therefore, always 0xffffffff */ if (__builtin_constant_p(__imm) && __imm > 255) compiletime_assert_XXX() This can result in tripping a BUILD_BUG_ON() in __BF_FIELD_CHECK() that checks that a given value is representable in one byte (interpreted as unsigned). FIELD_FIT() should return true or false at runtime for whether a value can fit for not. Don't break the build over a value that's too large for the mask. We'd prefer to keep the inlining and compiler optimizations though we know this case will always return false. Cc: stable@vger.kernel.org Fixes: 1697599ee301a ("bitfield.h: add FIELD_FIT() helper") Link: https://lore.kernel.org/kernel-hardening/CAK7LNASvb0UDJ0U5wkYYRzTAdnEs64HjXpEUL7d=V0CXiAXcNw@mail.gmail.com/ Reported-by: Masahiro Yamada Debugged-by: Sami Tolvanen Signed-off-by: Jakub Kicinski Signed-off-by: Nick Desaulniers Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- include/linux/bitfield.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/include/linux/bitfield.h +++ b/include/linux/bitfield.h @@ -64,7 +64,7 @@ */ #define FIELD_FIT(_mask, _val) \ ({ \ - __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_FIT: "); \ + __BF_FIELD_CHECK(_mask, 0ULL, 0ULL, "FIELD_FIT: "); \ !((((typeof(_mask))_val) << __bf_shf(_mask)) & ~(_mask)); \ })