Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp22031692rwd; Fri, 30 Jun 2023 03:01:53 -0700 (PDT) X-Google-Smtp-Source: APBJJlGzJmhZrN/tekMwlmYtB8vWf9qqCkOj9rMI5MZ1tpZzjRU1UhHTlpoammd2fVyuHFbYjZKl X-Received: by 2002:a92:c04d:0:b0:345:787a:cb27 with SMTP id o13-20020a92c04d000000b00345787acb27mr1798981ilf.21.1688119313502; Fri, 30 Jun 2023 03:01:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688119313; cv=none; d=google.com; s=arc-20160816; b=UebzOGallu8Jf0TKq2q5HoJTh5MxDlp4sPkC6smkKKVGyt4oItHSrHtb3b1p6lDcja p5UNG3fFCmagU2fhemX5lGX77Vz0jWPyKIqICFzSf+H3yCRBIQ1CkZfo50HAryw7e7t4 /U1262t2xFRcnyHAyNW8r3EyCWtYh0Z6OwFhaLPTpKMOOtQOYkbZf5aYljeCurBf9ADl RjAsZdr4lXd+OJAO3o6Bc64PvM+jWedp8BLlO4tppZK+rIvEIC1kb/ncnk2pSEZmbezb IS+MUgaQxCGsfU54u/sknMrtD9nSsZHcufoJOIuR2QxahwbzlDBhFk1RBpc/rXSWGN6d lloQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=GclBgXm9Q3XbGCOTf6wDEXPVGEyfn5qEyPiaLKc6uYM=; fh=Kd3XjUbkQ2AtF5MPjig/KxNRk+CKm7aEkadTrwB9pQs=; b=gY2MQ5WGO6MiDkWblALJFEHUfsz2sELD8kpKlUNej2flyHws2F7Xuy3RT2CToWBGw5 yfemW1DqOUh32pHFR7FlBMhkz4BFFfYDS3u9BY4RiVeSAJqE7AhXtDLYBu+Ukha/5o14 DmwgrQGedF6uCTqUF+lmvOLUTN5JmTo1eqGTtl3Gjbw2+7v0T0oPTzURQEs6XN9rgmFq 2BOKoptmlDhVDvnMcDwXgduxjP4ocEFrP/194qmIkj1/+4J+IFnff8ihNjjTAvswm0kR QyhL+7Rw+gvouaROBZjvnO5j5I5tLjf9Aj5VHZjdB261P8HyciAahhanIiBbXFoA7lx3 0YXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iROPQ3uy; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 32-20020a631560000000b005533c53f5cesi12402100pgv.27.2023.06.30.03.01.26; Fri, 30 Jun 2023 03:01:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-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=@linaro.org header.s=google header.b=iROPQ3uy; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232435AbjF3JrE (ORCPT + 99 others); Fri, 30 Jun 2023 05:47:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232562AbjF3JrD (ORCPT ); Fri, 30 Jun 2023 05:47:03 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4577F10FF for ; Fri, 30 Jun 2023 02:47:02 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3fa94ea1caaso14765085e9.1 for ; Fri, 30 Jun 2023 02:47:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688118421; x=1690710421; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=GclBgXm9Q3XbGCOTf6wDEXPVGEyfn5qEyPiaLKc6uYM=; b=iROPQ3uyJUbR73/EmgO0lq8jkRTRpaKxc9hXMOAfFJ6YSLlWACsaSPgz4BOsX/XyBm wifYby5SEIu+SProcw2R39cSI9PU9BKgmJux76CtYbtmLr3V2ia28uWftCJgqkBwXUJ0 A1z0qE46cVI9UGK7hSe+Hm0mJDmZv4CxMGaNL+2mLEZGI7TX9I8zVOZVEO9Ih7HA+A91 ulycw9uLpfM6MdQxkriibHCINZzd/lAPc1szOulfozPdr6kWOeTYQd4yaMWLlU+IkvXi vKjOcFP+ZR3UUhNnJ3Us79yWg40DfN4vSBTZYdUvTIN0gw/QHhkXchXziIlBgCOfVaRN iziw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688118421; x=1690710421; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GclBgXm9Q3XbGCOTf6wDEXPVGEyfn5qEyPiaLKc6uYM=; b=j0hGM1Q2zhvdHH3ehcx0sRHvXqcpcvcSMmr/MsxDA+1dBFKADSprXh5UBN0/38J5SO vTym8fEeZpQ9c4W8dQKPl2f2/rHT58R1XAF1O1ZSJSlUR87Ww6YlOHnsBNdNQziJ0xVE 8mpC7kB1hxCwL2r7/d02e5dCcQBEyMTb+eJz97xmmgBxnFLAyhXSWWFB7Lv/eMiHsTGj g8PBy8+ggh9YJgpa4M5gUTb2UPvzayIyNHvJGOlGEgSgvwLjggpGxOMn8DVNUITUUBla jUaf5zKPKKFM9bljJF5FgEsC509mWTdve5SpoN7yZjvN2ZSZ3dYSnwk+bzIFj/1m4DNO 4JZQ== X-Gm-Message-State: AC+VfDzNpSYX9Q4EjgYaWmtUxmdAxkxEASqp5L2olYme7wZ9lDcNRn8M 2DRqJCXQOzCeGYFcSBtdFPHdxw== X-Received: by 2002:a05:600c:3552:b0:3fa:94ea:583c with SMTP id i18-20020a05600c355200b003fa94ea583cmr7336415wmq.8.1688118420757; Fri, 30 Jun 2023 02:47:00 -0700 (PDT) Received: from localhost ([102.36.222.112]) by smtp.gmail.com with ESMTPSA id u6-20020a05600c210600b003fafe32c8f6sm12264726wml.10.2023.06.30.02.46.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 02:46:58 -0700 (PDT) Date: Fri, 30 Jun 2023 12:46:53 +0300 From: Dan Carpenter To: Trond Myklebust , Dmitry Antipov Cc: Anna Schumaker , Chuck Lever , Jeff Layton , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-nfs@vger.kernel.org, llvm@lists.linux.dev, kernel-janitors@vger.kernel.org Subject: [PATCH] SUNRPC: clean up integer overflow check Message-ID: <2390fdc8-13fa-4456-ab67-44f0744db412@moroto.mountain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Mailer: git-send-email haha only kidding X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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-nfs@vger.kernel.org This integer overflow check works as intended but Clang and GCC and warn about it when compiling with W=1. include/linux/sunrpc/xdr.h:539:17: error: comparison is always false due to limited range of data type [-Werror=type-limits] Use size_mul() to prevent the integer overflow. It silences the warning and it's cleaner as well. Reported-by: Dmitry Antipov Closes: https://lore.kernel.org/all/20230601143332.255312-1-dmantipov@yandex.ru/ Signed-off-by: Dan Carpenter --- Btw, since the Clang developers are automatically CC'd, here is how I silenced this type of false positive in Smatch: 1) Check that longs are 64 bit. 2) Check that the right hand side has a SIZE_MAX. SIZE_MAX is defined as -1UL so you want both the type and the value to match. 3) Then on the other the other side, check that the type is uint. I'm looking at this code now in Smatch and it's kind of ugly, and also there are some other places where I need to apply the same logic... include/linux/sunrpc/xdr.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/include/linux/sunrpc/xdr.h b/include/linux/sunrpc/xdr.h index f89ec4b5ea16..dbf7620a2853 100644 --- a/include/linux/sunrpc/xdr.h +++ b/include/linux/sunrpc/xdr.h @@ -775,9 +775,7 @@ xdr_stream_decode_uint32_array(struct xdr_stream *xdr, if (unlikely(xdr_stream_decode_u32(xdr, &len) < 0)) return -EBADMSG; - if (len > SIZE_MAX / sizeof(*p)) - return -EBADMSG; - p = xdr_inline_decode(xdr, len * sizeof(*p)); + p = xdr_inline_decode(xdr, size_mul(len, sizeof(*p))); if (unlikely(!p)) return -EBADMSG; if (array == NULL) -- 2.39.2