Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp4795232rwb; Mon, 31 Jul 2023 12:19:20 -0700 (PDT) X-Google-Smtp-Source: APBJJlEGmh8KDqFmaJMxVFH9oHHZ71mSqW5J5Dih1CXVJ9fBRC8afa5ZrT0X+RE89zsiPv/n65B3 X-Received: by 2002:a05:6a20:2591:b0:12f:dc31:a71e with SMTP id k17-20020a056a20259100b0012fdc31a71emr12805242pzd.56.1690831159862; Mon, 31 Jul 2023 12:19:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690831159; cv=none; d=google.com; s=arc-20160816; b=O5FvtEoeHa7qz3ysjcqpVGTeHaRRXSUiHe22b8UQCuUPOEmf3kw7J8oxnRFPzFxHLF lQ2hsKyVKp4yHJkhNZCRnEvIHTQNTOzIJdbxmRIAjtjmOa/dfyO3rnQfjCswbgHJMSB3 9xaB0gy8qwf0cDdYnlSmUttEWY4RFvPYQtYN+jSkADeSaghsu4NrDxdRVDfG+7NtjenQ xFEHTb9MaOFEOGj9qDGpEwBScu481ITVpSwYsyzyrdubdQKpsvJjQFImyYkaIfzZi5TI 1FliOK/Yey+iBLtDSuYW/OvDrP1uBBAQv9fQhAoc0r+oEU5Hjuhu/IgMIC0d7Vqo5twn iB5A== 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 :dkim-signature; bh=WNe4swavizqdV55R6wwaZgkXoPj5RhX8v6uZ3GcEnc4=; fh=cFLsAGnNe3zUanWWFWG7G85+YqpwihwX1aKMe9Hx5j8=; b=E4dbVk/ZxbZKu9OwNRSm8wuluLyGnm0y0gpqHV1i5qNxY/SZzGM+4sSsa/2ZuLM8EO 5ON+JhRXR+xgsf2fkiGVP0KgfiBZg8ixDAtryrjqcfOHQOIOwpqnxSNoESeStJ5lQX7k gXxrCvHQfec7k3pZrw7vApVnuAXUMdg7rHw/NbhHkRuqT/8xuA0qCRsuza7EzCC7e7bj cKP/iz4lJyw5pCUc2il4flYJthOb3lUlg6g+9pO1ot6blrEtNb0PxfGIZOMHD4/0GekS 5XTT/Qjz60fxjEd95kqWnIJCloJsf0J0FbeQuz8nQLqpA4AiJvmZmsgiIOI+yAOJGIYE qkew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=DgzSTM0L; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=MlhMg9D8; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z25-20020a056a001d9900b006870cd8a877si5909912pfw.172.2023.07.31.12.19.07; Mon, 31 Jul 2023 12:19:19 -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=@suse.cz header.s=susede2_rsa header.b=DgzSTM0L; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=MlhMg9D8; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230314AbjGaOf2 (ORCPT + 99 others); Mon, 31 Jul 2023 10:35:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232416AbjGaOf0 (ORCPT ); Mon, 31 Jul 2023 10:35:26 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2C5F123; Mon, 31 Jul 2023 07:35:24 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 92780221E0; Mon, 31 Jul 2023 14:35:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1690814123; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=WNe4swavizqdV55R6wwaZgkXoPj5RhX8v6uZ3GcEnc4=; b=DgzSTM0L1Ufxl+X74lXeV446U7HWIvlC5HrpOOkSrLPEq6yoJqFzeNBzwyyC4j8F+JfGnL 9l5HgKEtMgHGobGOIxmg/SoY2hKDfUWxMj6WAteoULKpdgMvR8Xyjuz0ZG8j9oVctDs9vd sJgPpVdr1XlAV7hrS6UA3MKoqcXUl9A= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1690814123; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=WNe4swavizqdV55R6wwaZgkXoPj5RhX8v6uZ3GcEnc4=; b=MlhMg9D8BuVbmKp+JlGPDMdK7QZv0idojdX4TldvRofjkbYbd59BXMX3U/T8cyemuyu33N HKAef52Q6qNL/zCQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 84A61133F7; Mon, 31 Jul 2023 14:35:23 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id YJ5XIKvGx2QzWwAAMHmgww (envelope-from ); Mon, 31 Jul 2023 14:35:23 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 11108A069C; Mon, 31 Jul 2023 16:35:23 +0200 (CEST) Date: Mon, 31 Jul 2023 16:35:23 +0200 From: Jan Kara To: Kees Cook Cc: "Gustavo A. R. Silva" , Jan Kara , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH][next] udf: Fix -Wstringop-overflow warnings Message-ID: <20230731143523.rfmn6oqob7pofyan@quack3> References: <202307121204.36EF4C1@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202307121204.36EF4C1@keescook> X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=no 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 Wed 12-07-23 12:05:34, Kees Cook wrote: > On Wed, Jul 12, 2023 at 12:25:45PM -0600, Gustavo A. R. Silva wrote: > > 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 > > --- > > 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, > > len is u32, "off" can't be less than blksize, so this all looks correct > to me. Thanks! > > Reviewed-by: Kees Cook Thanks! I've merged the patch to my tree. Honza -- Jan Kara SUSE Labs, CR