Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp4217158iog; Tue, 28 Jun 2022 11:20:37 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uh2fnozaX1xjbBv13CSuUd63fwqalm6HTQOsF8rSJa03/whUgwRynI6bYSP/QkBZZXyG43 X-Received: by 2002:a17:90a:66c1:b0:1e8:43ae:f7c0 with SMTP id z1-20020a17090a66c100b001e843aef7c0mr946517pjl.245.1656440437466; Tue, 28 Jun 2022 11:20:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656440437; cv=none; d=google.com; s=arc-20160816; b=PR3XfY6tobzhw+KmtGBOdvWhFLFdHQ4KWnQctw0sSeuZpp86EYLMQjemNuFFnYyxtb aGcSuxVYXGTivQkNlHN+B3bZP8Kq0GS6W/rGUpdq1OE5CLMAuN9g+zdXSy6Ml8F4fSxK WvyrlN1fgTTq3uoOOPrW4ktofj6DjGdrqFpUlZJ9/iwhgwRobPmHLruW9r4HlAsB7m1/ 9t0aDcW8anqFl+pSUod3E9YDFP42Ffps0RpXqOOLaiG4Vews/V8J8+SGgup8Nlod8kl7 x8Lx+WojoVWpQrRIADjQjjcyJEmK6Gy8mr52z7VzQyjOqSrC+8ReyjB2Cbfyvz8KRliC Dvew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Ifakbg1KSXljeCc2KlqlOz+XfzIBohlTVCEx+b5hm2Y=; b=YpEtiLHx1UPqLZo1U/p6jc2zDvnxuSCLVYdzegXSVTDOoXxnjeuKq+NOzH/gScdLbT 1X2j2uI9vOUwHeVCKg9fRYMv2QyoasvW2geWueofJYHqPpkfNGwX0NwUHKQWAx8z4eij s3xezmo772j5kiaqeConKR5aOH8474+JVD97u/BKk5raL0pKMpnfski494wqj1UbH6Yw MRH7tIkoBEDhM3Tk8fAxRnS5uePz/fPONUgSmWAbOOq4ng9X1WaI1rTPOzR03+QwgrLa Jrif/wzqOovRH4ziNAYQQsxHAYNnIu1SQWBJ+YeNXN1z3qIC3YUqHCAVj9hr7a9Jlxhe 9lNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Lpc3rw2l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s1-20020a170903214100b0016a3f860e43si16309364ple.264.2022.06.28.11.20.03; Tue, 28 Jun 2022 11:20:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Lpc3rw2l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232223AbiF1RzM (ORCPT + 99 others); Tue, 28 Jun 2022 13:55:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232530AbiF1RzC (ORCPT ); Tue, 28 Jun 2022 13:55:02 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0146DEA4 for ; Tue, 28 Jun 2022 10:55:00 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id n10so11795025plp.0 for ; Tue, 28 Jun 2022 10:54:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Ifakbg1KSXljeCc2KlqlOz+XfzIBohlTVCEx+b5hm2Y=; b=Lpc3rw2lUDFTgNuiFkNi7vJ3FOoQQ8sPNV+A/xT7kPgFFi5TelrrdXlIUbrL4j9GT+ 3+ei8DuymmFwmq4TMtVSFXVwj/BEoFuIu2AqPN9i6R5zOS+ndUs4OIvpg1Fj2tZP3rAs mZTqNdFC15vlNUFmjWu7inrraPu1BA3Mkzqts= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Ifakbg1KSXljeCc2KlqlOz+XfzIBohlTVCEx+b5hm2Y=; b=70X8Kyzg9VpcaVwjvhvVp82jQ2M1lHKflpovKiTsWD8vuGdyrJ7ThAInNelHmY1LPm sYQUWFHAHG5VDbicdYy8hUIvJQ/r/UkikYvY4AVNqYIX7Idj6s4GX6fcW66lmZrLXcia W4clqRotigKUCV+dqmjCF+OgKRifqXx1vzd2o94mUFLyTkbH7X3BG3gD3v+gbA5JLEHt lQl5W+V/Sbi3pDwWdaa50hZhqmfMKSyLu14xthTck8Qv3y35BTbH+uq53qgmv3mBbZ3a w0iTV5heVU91SbSA9NHmpHsQ3Sy8MqznXiaL8w5gsIddRr0ZWT9ygfQVtf+dlGqajQTF 6rYw== X-Gm-Message-State: AJIora84XKaBjAwrtwFma6qZIl+bVE46zzB9CnHBmMfpWXVxFkJABehg k10Rx3j3xPeEt4lVb+bO9nvYZw== X-Received: by 2002:a17:90b:3b52:b0:1ec:db2a:b946 with SMTP id ot18-20020a17090b3b5200b001ecdb2ab946mr838564pjb.229.1656438899502; Tue, 28 Jun 2022 10:54:59 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id f15-20020a170902ff0f00b0016a84d232a6sm5432810plj.46.2022.06.28.10.54.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jun 2022 10:54:59 -0700 (PDT) Date: Tue, 28 Jun 2022 10:54:58 -0700 From: Kees Cook To: Jason Gunthorpe Cc: Daniel Borkmann , "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org, x86@kernel.org, dm-devel@redhat.com, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-s390@vger.kernel.org, kvm@vger.kernel.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-can@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux1394-devel@lists.sourceforge.net, io-uring@vger.kernel.org, lvs-devel@vger.kernel.org, linux-mtd@lists.infradead.org, kasan-dev@googlegroups.com, linux-mmc@vger.kernel.org, nvdimm@lists.linux.dev, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, linux-perf-users@vger.kernel.org, linux-raid@vger.kernel.org, linux-sctp@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-usb@vger.kernel.org, virtualization@lists.linux-foundation.org, v9fs-developer@lists.sourceforge.net, linux-rdma@vger.kernel.org, alsa-devel@alsa-project.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH][next] treewide: uapi: Replace zero-length arrays with flexible-array members Message-ID: <202206281009.4332AA33@keescook> References: <20220627180432.GA136081@embeddedor> <6bc1e94c-ce1d-a074-7d0c-8dbe6ce22637@iogearbox.net> <20220628004052.GM23621@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220628004052.GM23621@ziepe.ca> X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 27, 2022 at 09:40:52PM -0300, Jason Gunthorpe wrote: > On Mon, Jun 27, 2022 at 08:27:37PM +0200, Daniel Borkmann wrote: > > [...] > > Fyi, this breaks BPF CI: > > > > https://github.com/kernel-patches/bpf/runs/7078719372?check_suite_focus=true > > > > [...] > > progs/map_ptr_kern.c:314:26: error: field 'trie_key' with variable sized type 'struct bpf_lpm_trie_key' not at the end of a struct or class is a GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end] > > struct bpf_lpm_trie_key trie_key; > > ^ The issue here seems to be a collision between "unknown array size" and known sizes: struct bpf_lpm_trie_key { __u32 prefixlen; /* up to 32 for AF_INET, 128 for AF_INET6 */ __u8 data[0]; /* Arbitrary size */ }; struct lpm_key { struct bpf_lpm_trie_key trie_key; __u32 data; }; This is treating trie_key as a header, which it's not: it's a complete structure. :) Perhaps: struct lpm_key { __u32 prefixlen; __u32 data; }; I don't see anything else trying to include bpf_lpm_trie_key. > > This will break the rdma-core userspace as well, with a similar > error: > > /usr/bin/clang-13 -DVERBS_DEBUG -Dibverbs_EXPORTS -Iinclude -I/usr/include/libnl3 -I/usr/include/drm -g -O2 -fdebug-prefix-map=/__w/1/s=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -Wmissing-prototypes -Wmissing-declarations -Wwrite-strings -Wformat=2 -Wcast-function-type -Wformat-nonliteral -Wdate-time -Wnested-externs -Wshadow -Wstrict-prototypes -Wold-style-definition -Werror -Wredundant-decls -g -fPIC -std=gnu11 -MD -MT libibverbs/CMakeFiles/ibverbs.dir/cmd_flow.c.o -MF libibverbs/CMakeFiles/ibverbs.dir/cmd_flow.c.o.d -o libibverbs/CMakeFiles/ibverbs.dir/cmd_flow.c.o -c ../libibverbs/cmd_flow.c > In file included from ../libibverbs/cmd_flow.c:33: > In file included from include/infiniband/cmd_write.h:36: > In file included from include/infiniband/cmd_ioctl.h:41: > In file included from include/infiniband/verbs.h:48: > In file included from include/infiniband/verbs_api.h:66: > In file included from include/infiniband/ib_user_ioctl_verbs.h:38: > include/rdma/ib_user_verbs.h:436:34: error: field 'base' with variable sized type 'struct ib_uverbs_create_cq_resp' not at the end of a struct or class is a GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end] > struct ib_uverbs_create_cq_resp base; > ^ > include/rdma/ib_user_verbs.h:644:34: error: field 'base' with variable sized type 'struct ib_uverbs_create_qp_resp' not at the end of a struct or class is a GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end] > struct ib_uverbs_create_qp_resp base; This looks very similar, a struct of unknown size is being treated as a header struct: struct ib_uverbs_create_cq_resp { __u32 cq_handle; __u32 cqe; __aligned_u64 driver_data[0]; }; struct ib_uverbs_ex_create_cq_resp { struct ib_uverbs_create_cq_resp base; __u32 comp_mask; __u32 response_length; }; And it only gets used here: DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_CQ, ib_uverbs_create_cq, UAPI_DEF_WRITE_UDATA_IO( struct ib_uverbs_create_cq, struct ib_uverbs_create_cq_resp), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UAPI_DEF_METHOD_NEEDS_FN(create_cq)), which must also be assuming it's a header. So probably better to just drop the driver_data field? I don't see anything using it (that I can find) besides as a sanity-check that the field exists and is at the end of the struct. -- Kees Cook