From patchwork Wed Jul 12 18:25:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 119322 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1337380vqm; Wed, 12 Jul 2023 11:29:59 -0700 (PDT) X-Google-Smtp-Source: APBJJlH6W8e3wG003OBI5XgPjIOkMmVw68txoHFXEt+4Vz8Oas1KiZq5YqJCsgzrtySY/NfVa0xF X-Received: by 2002:a05:6512:2034:b0:4fb:7933:dd4f with SMTP id s20-20020a056512203400b004fb7933dd4fmr15199750lfs.56.1689186599346; Wed, 12 Jul 2023 11:29:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689186599; cv=none; d=google.com; s=arc-20160816; b=jPpg8J+ww4rZ5gSe1Lv4UEYEeJB7vinONADKLO6toCtG2miWVjpYpSOhks0irdeBsk +0ny6hwf4GKtczVL3GxSQbMcu4ajwTj4ihsMfiv6dV+v6vtqiZJ8uQ3qxI6OQ/yRVh0L iHwtO6hvLXyvvvOUDEyB9Vvnmj2XtieIsiTm/qtEKVCE9obLR8fZ7NStohLhPkb5YvC2 aQ2T65rCJAPr+Kgm6SSnvFlgBJU7waekgeHEkfgdVCosC8F4Atv8ITD/OtKsNaFOoOED OUvCvyEAHw3KsT/fC5BImWmq42OmI+79pjf1aJ9xcCaik5+W+aHTtk0FIRC0ZOUYSddd aT6Q== 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=DjinBbzKlw3HCRFqZzO2Zu6rITRZ5ZY3pEkTpsQ4J4Y=; fh=vLSLkxsjMzrXcCzWVUHY18xL1omLnE6gP4XTBwbA/bk=; b=kWT/nl1+lzliyRTNFQCZ10nT0WqNTEFR7NhBhkuE6LiFMHix/dSGZuX8p+sQRFpAVe UvrFFzOz/n7GCJKjxGzugWNBPH0sBvGy/w5obB2EDyNhb/amAyxDoWgqNTf+++Y9vKpo oyuupeugShZcHIm0pIZZ+nUQN9OQO49GuNsET8BbGCRwDj012Xplx1T5rbtf5vUZOjxF yei6LTmdoU5GikxQWaQEXDxW6c0Gb5B06JEnyPY+U5TZvDXZIYvmkmckalV5cCETj6xj MEZPxf0GK9PXAodW4pfRpowkcGI/Bq0ZiFMjIIuX7ZGrt1caW+peouj2Pbv56c5bIBgd sWBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BDqP0+og; 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=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a18-20020aa7cf12000000b0051dd2d6be5esi4850124edy.507.2023.07.12.11.29.34; Wed, 12 Jul 2023 11:29:59 -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=@kernel.org header.s=k20201202 header.b=BDqP0+og; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232016AbjGLSY5 (ORCPT + 99 others); Wed, 12 Jul 2023 14:24:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229649AbjGLSY4 (ORCPT ); Wed, 12 Jul 2023 14:24:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64FEE1BE3; Wed, 12 Jul 2023 11:24:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EAADE6189F; Wed, 12 Jul 2023 18:24:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6E98C433C8; Wed, 12 Jul 2023 18:24:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689186294; bh=oiL8B5T0SF7z89hecNy7VIEQawHKk0jVhieQ+mQfndw=; h=Date:From:To:Cc:Subject:From; b=BDqP0+ogAMJEpRGdPK3N+vTGpYBYsDyQIiifRNqv1xyWIUnXS3Whnp/ZJcxMD2PzU vcnya0Umb/RBkCNhcsI3/lriYJj1y6EGBvV5eX2jPXEIOkzioX0cNlCIN0euhDdDaE b2YxwZstHOlImIXjFY4e4F21Lar4uil/Z7OADLfv/z9ijlutaAr8203dJOk3nuB6iR w6+P6iDVfAWyy80OnY//7/8FR/CaJ6DLY05pnt9FizZSo/4BPZnJphQ6FZkugVA0bE +dWjugeNq6++3Boy/w1UrlQ+9hi0z7+vOVo3teNTLZksBtxctr7D8Di8S6bHl1i+HW Alz75aGcJBmPg== Date: Wed, 12 Jul 2023 12:25:45 -0600 From: "Gustavo A. R. Silva" To: Jan Kara Cc: linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] udf: Fix -Wstringop-overflow warnings Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771240527479095386 X-GMAIL-MSGID: 1771240527479095386 Use unsigned type in call to macro mint_t(). This avoids confusing the compiler about possible negative values that would cause the value in _len_ to wrap around. Fixes the following -Wstringop-warnings seen when building ARM architecture with allyesconfig (GCC 13): fs/udf/directory.c: In function 'udf_copy_fi': include/linux/fortify-string.h:57:33: warning: '__builtin_memcpy' specified bound between 2147483648 and 4294967295 exceeds maximum object size 2147483647 [-Wstringop-overflow=] 57 | #define __underlying_memcpy __builtin_memcpy | ^ include/linux/fortify-string.h:648:9: note: in expansion of macro '__underlying_memcpy' 648 | __underlying_##op(p, q, __fortify_size); \ | ^~~~~~~~~~~~~ include/linux/fortify-string.h:693:26: note: in expansion of macro '__fortify_memcpy_chk' 693 | #define memcpy(p, q, s) __fortify_memcpy_chk(p, q, s, \ | ^~~~~~~~~~~~~~~~~~~~ fs/udf/directory.c:99:9: note: in expansion of macro 'memcpy' 99 | memcpy(&iter->fi, iter->bh[0]->b_data + off, len); | ^~~~~~ include/linux/fortify-string.h:57:33: warning: '__builtin_memcpy' specified bound between 2147483648 and 4294967295 exceeds maximum object size 2147483647 [-Wstringop-overflow=] 57 | #define __underlying_memcpy __builtin_memcpy | ^ include/linux/fortify-string.h:648:9: note: in expansion of macro '__underlying_memcpy' 648 | __underlying_##op(p, q, __fortify_size); \ | ^~~~~~~~~~~~~ include/linux/fortify-string.h:693:26: note: in expansion of macro '__fortify_memcpy_chk' 693 | #define memcpy(p, q, s) __fortify_memcpy_chk(p, q, s, \ | ^~~~~~~~~~~~~~~~~~~~ fs/udf/directory.c:99:9: note: in expansion of macro 'memcpy' 99 | memcpy(&iter->fi, iter->bh[0]->b_data + off, len); | ^~~~~~ AR fs/udf/built-in.a This helps with the ongoing efforts to globally enable -Wstringop-overflow. Link: https://github.com/KSPP/linux/issues/329 Signed-off-by: Gustavo A. R. Silva Reviewed-by: Kees Cook --- fs/udf/directory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/udf/directory.c b/fs/udf/directory.c index 1c775e072b2f..93153665eb37 100644 --- a/fs/udf/directory.c +++ b/fs/udf/directory.c @@ -95,7 +95,7 @@ static int udf_copy_fi(struct udf_fileident_iter *iter) } off = iter->pos & (blksize - 1); - len = min_t(int, sizeof(struct fileIdentDesc), blksize - off); + len = min_t(u32, sizeof(struct fileIdentDesc), blksize - off); memcpy(&iter->fi, iter->bh[0]->b_data + off, len); if (len < sizeof(struct fileIdentDesc)) memcpy((char *)(&iter->fi) + len, iter->bh[1]->b_data,