Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp1626292rwb; Fri, 13 Jan 2023 15:15:59 -0800 (PST) X-Google-Smtp-Source: AMrXdXuj+lI794KJtG6NRVqgQwnkbyeUP45usQccEW0u01bjt85fKzd9eeltIoUc2HAdwcy/CODW X-Received: by 2002:a17:907:a0c9:b0:868:d72f:d106 with SMTP id hw9-20020a170907a0c900b00868d72fd106mr7150928ejc.47.1673651758981; Fri, 13 Jan 2023 15:15:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673651758; cv=none; d=google.com; s=arc-20160816; b=XQ8339Vmt0pNSD0C0qObAsZOwSI0JSN8vDFtSHEu+DrlIasKxPGOLbvFe4DnTlvT7M g1sF0/sCiLLK3qb/MIn1cWnSARnX0s7twgIf5b9Q+peyzXJjqTAbetbWoXduH9/cLrLG 9+uVfu/tB/jHyL1h8aVSjqQOjWU+iob9o8w0+q0501UpA073Sej7NWOlqEC/fRhaQSyI PH5MbKmjmNNSPHE/B/1x45US27VPIDT+Qa9aXRnQPzVnbatriOzaAPzXyk9H9Fw0lUV+ Ben2GoAQEJJ+TMRc09OhF/XIfCjfXDjul2Ify/wHpAjmzONHESugopxEP84lhklND/Rd AKWA== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=CAQbYGMaML5fa/DHmVz3EfKdwA/KXc1FwDFGQHrppL0=; b=ClmtxPNuVHBsw1gUYnbSVzHclLhtFP3XE6rNIXdlsD5iU1JRRAEU0DNaWaRhHb1KUM WmXs0yHwwxSfci33h7XP2MN/bunUlt6N4rT3w2jvPbkNawOryzjLnSXUJJUPL5A7XiHV 4JirzwNXYblDPubzsApUJH96N1FzkR0NPnMWM3x8CkAQVK5Ny7EKNphL/oFKgSVtR8M4 AU8ZX4edGBJKCZLS4KIsw4pn31AEP+KA7jywNvfzyJt/BocnrTI/t9rfPx1jAcxYitZq OFelwqCZoo5q6iH8MRYnI2skd54e724sNDWN0DDoj8XJL2qVMud0qL+2YO7k1Vdw6d2m tC0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=lWOjbvh4; 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 ga21-20020a1709070c1500b007ae26c753edsi12959577ejc.52.2023.01.13.15.15.22; Fri, 13 Jan 2023 15:15:58 -0800 (PST) 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=lWOjbvh4; 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 S230525AbjAMXBg (ORCPT + 52 others); Fri, 13 Jan 2023 18:01:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230036AbjAMXBc (ORCPT ); Fri, 13 Jan 2023 18:01:32 -0500 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E34F67ECB7 for ; Fri, 13 Jan 2023 15:01:28 -0800 (PST) Received: by mail-pf1-x42a.google.com with SMTP id i65so13770714pfc.0 for ; Fri, 13 Jan 2023 15:01:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=CAQbYGMaML5fa/DHmVz3EfKdwA/KXc1FwDFGQHrppL0=; b=lWOjbvh4IuNBwa2ZzT3rgGJypVyC6Zc1Wqnrkimn/SW2ehJDGWbXXULefjgfyeo5Qd Ws/jQ8cVwT2F36JNS9xaTdmsIAN7AC/ZZFbjr86PEUU0ytQMeSqtMi+y/vQl+/pgo4U8 E46GRUr/SaBCvobUxYpqR1y/6gYHKe34xATJo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CAQbYGMaML5fa/DHmVz3EfKdwA/KXc1FwDFGQHrppL0=; b=PYhtC+zNLEIXv6xBKZc5lciOZ7TAoxU6axPa6236u9FD8JQ+94UI6Hu/xQtVotFlBz 3ZS2Gu6pgy9BKWgMhe6z900IR1i2lgTyLX4yi2Bp8sjfM2TLMjj8ipXyM3q1fFqSwvfk 4uf9gXk7dBrCCQdiEwey9IrkGCWbk9Wm6X7vNlvyqDemcxvwjRMsoeqNDDok948dH8+m aTc2wR76gCv1T8DBavuIht+w1jXcKIf6jK/xvCY4bj7CvInHCs3Vvu5kc23OMrPZNInU 1OJGtV5/pxsNgmdD/lKSqYdU3bdk1EGOKMe2zN+2Q0vZisixbjGhl8rDa38V6yN0NhCW brtA== X-Gm-Message-State: AFqh2kqhm0ywh8gly4/1oyEJyhrz9FbAz6vqhE2Sof1MpRFDB2B1n44y JFuKjEG/d/WfANtp2gNv+Wt2hw== X-Received: by 2002:a05:6a00:4212:b0:583:fb14:ddc1 with SMTP id cd18-20020a056a00421200b00583fb14ddc1mr28709488pfb.17.1673650888393; Fri, 13 Jan 2023 15:01:28 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id v67-20020a622f46000000b00581ad007a9fsm14121533pfv.153.2023.01.13.15.01.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 15:01:27 -0800 (PST) Date: Fri, 13 Jan 2023 15:01:26 -0800 From: Kees Cook To: Jason Gunthorpe Cc: Yupeng Li , tariqt@nvidia.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, Caicai Subject: Re: [PATCH 1/1] net/mlx4: Fix build error use array_size() helper in copy_to_user() Message-ID: <202301131453.D93C967D4@keescook> References: <20230107072725.673064-1-liyupeng@zbhlos.com> <202301131039.7354AD35CF@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <202301131039.7354AD35CF@keescook> X-Spam-Status: No, score=-2.1 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 autolearn=ham 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 Fri, Jan 13, 2023 at 10:41:01AM -0800, Kees Cook wrote: > On Mon, Jan 09, 2023 at 09:51:18AM -0400, Jason Gunthorpe wrote: > > On Sat, Jan 07, 2023 at 03:27:25PM +0800, Yupeng Li wrote: > > > When CONFIG_64BIT was disabled, check_copy_size() was declared with > > > attribute error: copy source size is too small, array_size() for 32BIT > > > was wrong size, some compiled msg with error like: > > > > > > CALL scripts/checksyscalls.sh > > > CC [M] drivers/net/ethernet/mellanox/mlx4/cq.o > > > In file included from ./arch/x86/include/asm/preempt.h:7, > > > from ./include/linux/preempt.h:78, > > > from ./include/linux/percpu.h:6, > > > from ./include/linux/context_tracking_state.h:5, > > > from ./include/linux/hardirq.h:5, > > > from drivers/net/ethernet/mellanox/mlx4/cq.c:37: > > > In function ‘check_copy_size’, > > > inlined from ‘copy_to_user’ at ./include/linux/uaccess.h:168:6, > > > inlined from ‘mlx4_init_user_cqes’ at drivers/net/ethernet/mellanox/mlx4/cq.c:317:9, > > > inlined from ‘mlx4_cq_alloc’ at drivers/net/ethernet/mellanox/mlx4/cq.c:394:10: > > > ./include/linux/thread_info.h:228:4: error: call to ‘__bad_copy_from’ declared with attribute error: copy source size is too small > > > 228 | __bad_copy_from(); > > > | ^~~~~~~~~~~~~~~~~ > > > make[6]: *** [scripts/Makefile.build:250:drivers/net/ethernet/mellanox/mlx4/cq.o] 错误 1 > > > make[5]: *** [scripts/Makefile.build:500:drivers/net/ethernet/mellanox/mlx4] 错误 2 > > > make[5]: *** 正在等待未完成的任务.... > > > make[4]: *** [scripts/Makefile.build:500:drivers/net/ethernet/mellanox] 错误 2 > > > make[3]: *** [scripts/Makefile.build:500:drivers/net/ethernet] 错误 2 > > > make[3]: *** 正在等待未完成的任务.... > > > make[2]: *** [scripts/Makefile.build:500:drivers/net] 错误 2 > > > make[2]: *** 正在等待未完成的任务.... > > > make[1]: *** [scripts/Makefile.build:500:drivers] 错误 2 > > > make: *** [Makefile:1992:.] 错误 2 > > > > > > Signed-off-by: Yupeng Li > > > Reviewed-by: Caicai > > > --- > > > drivers/net/ethernet/mellanox/mlx4/cq.c | 4 ++++ > > > 1 file changed, 4 insertions(+) > > > > > > diff --git a/drivers/net/ethernet/mellanox/mlx4/cq.c b/drivers/net/ethernet/mellanox/mlx4/cq.c > > > index 4d4f9cf9facb..7dadd7227480 100644 > > > --- a/drivers/net/ethernet/mellanox/mlx4/cq.c > > > +++ b/drivers/net/ethernet/mellanox/mlx4/cq.c > > > @@ -315,7 +315,11 @@ static int mlx4_init_user_cqes(void *buf, int entries, int cqe_size) > > > } > > > } else { > > > err = copy_to_user((void __user *)buf, init_ents, > > > +#ifdef CONFIG_64BIT > > > array_size(entries, cqe_size)) ? > > > +#else > > > + entries * cqe_size) ? > > > +#endif > > > -EFAULT : 0; > > > > This can't possibly make sense, Kees? > > Uuuuh, that's really weird. What compiler version and arch? I'll see if > I can reproduce this. I can't reproduce this. I'm assuming this is being seen on a 32-bit loongarch build? I have no idea how to get that compiler. Neither Debian nor Fedora seem to package it. (It looks like it was added in GCC 12?) Perhaps it's just "mips"? But I also can't figure out how to choose a 32-bit mips build. Wheee. Anyway, I would assume this is a compiler bug around inlining or the check_mul_overflow implementation? static inline size_t __must_check size_mul(size_t factor1, size_t factor2) { size_t bytes; if (check_mul_overflow(factor1, factor2, &bytes)) return SIZE_MAX; return bytes; } #define array_size(a, b) size_mul(a, b) -Kees -- Kees Cook