Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp703081rdb; Fri, 6 Oct 2023 16:59:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFVK4NkfFNwfE7wkAVFB+/CJ8G/jRQbMwwqHdSOLllN+DtEYxCa69cKlarxDbRh8nyP4YQs X-Received: by 2002:a05:620a:3887:b0:76c:8998:1866 with SMTP id qp7-20020a05620a388700b0076c89981866mr8554875qkn.40.1696636741995; Fri, 06 Oct 2023 16:59:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696636741; cv=none; d=google.com; s=arc-20160816; b=JLnIpmLM8sRDl18U1liBfgpQpqxrYYZPVgH8rnaTRwmI3Pn8dcceF1qM+XtzZM9sQl b93fDbYPPX17pQIjsrgkSCdvVCnIgKxzwhxXguW/xbMiv6AxXECigsU9LhEc4083cDOb 1IRvVRHY4YpHX3A5OKiJZiHpaTADp5y6LyoWF3CLk8det1+X9h8EGQDPUkNmQxaBJi0U QXEZIX8Rfix1ZaqvfLECS1pcu+mSzrn2+AYIlYvH1cxld4ZaNNG/eh5cZ4zK7UitEAIb Hf4UeeHG4+4uMnorUs+yEMFBmsJXFBzH3rQBhMMgQPVFZ4gdi0OL4vqmKiOiqU9Olq+d l9Ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:mime-version:date :dkim-signature:message-id; bh=dDT9aDLVsvLOYEEw3RfZqvCDnW1m/iupVkMyeiBZkag=; fh=+75XrcmPK8kqfNw2iG4nYoynDstSx2ctrU2DoogGT+Q=; b=B90vJm0NtNAO4iiMeFLVGQjPz7OPYI56TSwY4J7tbkTcMEr91mb9DfBoVn5fjYdMev O7wTHnaxcVxZLCHbmQA2gYqZr54e92cJz71L/Uy3rTY3UhZE97bZyFFeAPL+AQWHT6+u eSZuez7NpRETMGGpEwCyHjAZ1qy6t/N9yDn3ja4fScIfBeGqtyg9ASy6exwXXrliKNwg tkpKE55w+V2DnDFgzeQL+N+cjcdCFCCCZZCYPJ/GsdzSVCRuewU+CCPFR0lmZ/LYpIDQ mhqUAiqHXOOf3HTnAodJAP+wxQFRWMjZbhT5vctBnSv0yLOVdjF+O8lL5p0AWlUP7WG5 hDRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=bRp8bZaQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id b18-20020a656692000000b0056c297d163asi4750525pgw.523.2023.10.06.16.59.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 16:59:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=bRp8bZaQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 9E36C85C7A84; Fri, 6 Oct 2023 16:58:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233958AbjJFX6g (ORCPT + 99 others); Fri, 6 Oct 2023 19:58:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233923AbjJFX6f (ORCPT ); Fri, 6 Oct 2023 19:58:35 -0400 X-Greylist: delayed 82654 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Fri, 06 Oct 2023 16:58:32 PDT Received: from out-206.mta1.migadu.com (out-206.mta1.migadu.com [IPv6:2001:41d0:203:375::ce]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9654EBF for ; Fri, 6 Oct 2023 16:58:32 -0700 (PDT) Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1696636709; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dDT9aDLVsvLOYEEw3RfZqvCDnW1m/iupVkMyeiBZkag=; b=bRp8bZaQOTZ0RK9xi0lir38QHE8v8QBKgJcvmeoeYaNR/IEA1nPc6gk1SCWnOrW3geE8q5 SFeTWujgrha+ovCuE032fSZ5wTFtw5twahhoma/m66jMNpq33ud9K9jtJClu9970B1GWn+ XA3wZYQCtHyiI655HDSBavI2iGp6Mfg= Date: Fri, 6 Oct 2023 16:58:18 -0700 MIME-Version: 1.0 Subject: Re: [PATCH bpf v3] net/xdp: fix zero-size allocation warning in xskq_create() Content-Language: en-US To: Andrew Kanner Cc: linux-kernel-mentees@lists.linuxfoundation.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+fae676d3cf469331fc89@syzkaller.appspotmail.com, syzbot+b132693e925cbbd89e26@syzkaller.appspotmail.com, bjorn@kernel.org, magnus.karlsson@intel.com, maciej.fijalkowski@intel.com, jonathan.lemon@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, aleksander.lobakin@intel.com, xuanzhuo@linux.alibaba.com, ast@kernel.org, hawk@kernel.org, john.fastabend@gmail.com, daniel@iogearbox.net References: <20231005193548.515-1-andrew.kanner@gmail.com> <7aa47549-5a95-22d7-1d03-ffdd251cec6d@linux.dev> <651fb2a8.c20a0220.8d6c3.0fd9@mx.google.com> <57c35480-983d-2056-1d72-f6e555069b83@linux.dev> <6520971d.a70a0220.758e3.8cf7@mx.google.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Martin KaFai Lau In-Reply-To: <6520971d.a70a0220.758e3.8cf7@mx.google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Fri, 06 Oct 2023 16:58:59 -0700 (PDT) X-Spam-Level: ** On 10/6/23 4:24 PM, Andrew Kanner wrote: >> Thanks for the explanation, so iiuc it means it will overflow the >> struct_size() first because of the is_power_of_2(nentries) requirement? >> Could you help adding some comment to explain? Thanks. >> > The overflow happens because there's no upper limit for nentries > (userspace input). Let me add more context, e.g. from net/xdp/xsk.c: > > static int xsk_setsockopt(struct socket *sock, int level, int optname, > sockptr_t optval, unsigned int optlen) > { > [...] > if (copy_from_sockptr(&entries, optval, sizeof(entries))) > return -EFAULT; > [...] > err = xsk_init_queue(entries, q, false); > [...] > } > > 'entries' is passed to xsk_init_queue() and there're 2 checks: for 0 > and is_power_of_2() only, no upper bound check: > > static int xsk_init_queue(u32 entries, struct xsk_queue **queue, > bool umem_queue) > { > struct xsk_queue *q; > > if (entries == 0 || *queue || !is_power_of_2(entries)) > return -EINVAL; > > q = xskq_create(entries, umem_queue); > if (!q) > return -ENOMEM; > [...] > } > > The 'entries' value is next passed to struct_size() in > net/xdp/xsk_queue.c. If it's large enough - SIZE_MAX will be returned. All make sense. I was mostly asking to add a comment at the "if (unlikely(size == SIZE_MAX)" check to explain this details on why checking SIZE_MAX is enough.