From patchwork Fri Oct 12 09:09:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 10638137 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6B29814E2 for ; Fri, 12 Oct 2018 09:09:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A2C22BB0B for ; Fri, 12 Oct 2018 09:09:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4DE4B2BB19; Fri, 12 Oct 2018 09:09:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B231A2BB0B for ; Fri, 12 Oct 2018 09:09:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728122AbeJLQks (ORCPT ); Fri, 12 Oct 2018 12:40:48 -0400 Received: from s3.sipsolutions.net ([144.76.43.62]:45856 "EHLO sipsolutions.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727808AbeJLQkr (ORCPT ); Fri, 12 Oct 2018 12:40:47 -0400 Received: by sipsolutions.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.91) (envelope-from ) id 1gAtRd-0007zJ-BK; Fri, 12 Oct 2018 11:09:17 +0200 From: Johannes Berg To: linux-wireless@vger.kernel.org, netdev@vger.kernel.org Cc: John Garry , Johannes Berg Subject: [PATCH] netlink: replace __NLA_ENSURE implementation Date: Fri, 12 Oct 2018 11:09:04 +0200 Message-Id: <20181012090904.24547-1-johannes@sipsolutions.net> X-Mailer: git-send-email 2.14.4 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Johannes Berg John Garry reported that when we actually use the current implementation of __NLA_ENSURE, he gets compiler warnings from -Wvla since there's an array in there, and for some reason the compiler cannot immediately prove that its size is constant. It must eventually be able to prove it as we can use this inside an initializer for a constant, but the warning still shows up for him. I haven't been able to reproduce the warning on gcc in any case that actually should compile, though in the case that a non-constant value is actually passed I do see both the VLA warning as well as the non-constant initializer error. This was with both gcc 7.3.1 (which John also reported to be using) and 8.1. However, since we already have BUILD_BUG_ON_ZERO() and I just missed it when implementing this, just use it, which avoids this whole issue because it uses the bitfield trick to force compilation errors, rather than the array trick. Reported-by: John Garry Fixes: 3e48be05f3c7 ("netlink: add attribute range validation to policy") Signed-off-by: Johannes Berg --- include/net/netlink.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/net/netlink.h b/include/net/netlink.h index 589683091f16..094012174b6f 100644 --- a/include/net/netlink.h +++ b/include/net/netlink.h @@ -311,7 +311,7 @@ struct nla_policy { #define NLA_POLICY_NESTED_ARRAY(maxattr, policy) \ { .type = NLA_NESTED_ARRAY, .validation_data = policy, .len = maxattr } -#define __NLA_ENSURE(condition) (sizeof(char[1 - 2*!(condition)]) - 1) +#define __NLA_ENSURE(condition) BUILD_BUG_ON_ZERO(!(condition)) #define NLA_ENSURE_INT_TYPE(tp) \ (__NLA_ENSURE(tp == NLA_S8 || tp == NLA_U8 || \ tp == NLA_S16 || tp == NLA_U16 || \