Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp7258565rwi; Mon, 24 Oct 2022 12:00:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7vxdV/3xqQNMrExPezKUxIKceSh3F9pHdfOvUdQF7jF4abkBp0Ve8ZJW9yMk08Zf39wXAR X-Received: by 2002:a17:903:2286:b0:185:3948:be93 with SMTP id b6-20020a170903228600b001853948be93mr35281387plh.121.1666638035799; Mon, 24 Oct 2022 12:00:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666638035; cv=none; d=google.com; s=arc-20160816; b=mQKjYeHgxU4EyjihHmnVgvFsJuTSUT/ZT5pEQ3+KTpFqG/kn8F+bcL9yeW8X83unx+ BeqxDBXJaOyXBljMuA0zBN0zNhhiqlu7RkwM9kVseFL3026UjAO1uHfpo6hTi4FAjQm8 0zE98QPc9n8naaEF/v3eC/trxrA3HiLeYDrIlrW+EkcQzfmpBxOq3OA9ZL45k6ShByyY JbfBOcJcWsqYpzmqs323gZP9aUcdlJzr6rb3J6GINgdu+YU349LXGLM01kcgPQKZC5PF 0n6vFpv5ladGMELOOh9pI9GYLlpBhuif4KBUUR22i4w6k44EJIAyGVqMNb5i/F9Kpjmb Bv0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rfwpvweGi1Ucx8HQshpxviuI+RQIpmr8edZSxz2ZyS8=; b=uXYVDwRFWokRpcGlJsDICz/jy51tFL903S9oWAlmSMTKobVtnxj3JUNrkyMhz+qkhR 8wCUsPt7fFtxvPvW3/fNWxoqhOGptVz6OeT7rFp8ZspFtncdC+0cMaLofBb9DvjQfcXq 9LKNOcd0RUFLaFSkYzZMsPMI4KVHn8gRkkFtLQdrvGaaSQ+oRzWTQEMn6YasFedHcstd UClASOPtdtXuucz7exJGkv7aXJs/OGFRfhKx0SCBwtelVr0zCISR5p1ZH6c3wqTom2K2 8e4EI2ZluUJEuxpQTRb2eLCSjl558jVDfaTjPBCqQSGHHctlEoQ9jCr164UV/dt6QvVM yt+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=cRHBNse3; 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 g191-20020a636bc8000000b0043941763eadsi210720pgc.835.2022.10.24.12.00.22; Mon, 24 Oct 2022 12:00:35 -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=@chromium.org header.s=google header.b=cRHBNse3; 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 S232133AbiJXSkn (ORCPT + 99 others); Mon, 24 Oct 2022 14:40:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231874AbiJXSkT (ORCPT ); Mon, 24 Oct 2022 14:40:19 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A257A8365 for ; Mon, 24 Oct 2022 10:22:20 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id ez6so8621707pjb.1 for ; Mon, 24 Oct 2022 10:22:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rfwpvweGi1Ucx8HQshpxviuI+RQIpmr8edZSxz2ZyS8=; b=cRHBNse3LDl7knerfXifthateEO5UMiwl8a2j41s/BW6mt9+2V3xiOBC2HFZioyyJH i+yc2YUJzK2L4RQsm7M3cbP6yJybDkXRaeZV/j2urLVjf0krimJh45HbXtqBVhQL1Iqq JmXAxZ1V4PIuXYnDklyo4doMEr87jbivpe/Vc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rfwpvweGi1Ucx8HQshpxviuI+RQIpmr8edZSxz2ZyS8=; b=EWBu6cBAZB8xztusCBkReEzuVr1wvhomECDsFEKRcmm4LD54I30QgXFRcQLOF8PRvI ViUg2sLpHfL9B1G8GfpqKX67Mq9a+hEgmO5E+XrT7pI8Vpw8KHFDL7Q+m1YAvgroLP9Y EKW8rCCFQ+qefhFnUWILPqa5j0yRoHQgMB/qZMm3gfQ9IbkoTRQJsBFlpcrde2s4hqX/ 3VS0mK8ry/TqASdWu+BL+9GHyDRif3k9qYeDQ9uM6a//YNt1NJEY4Z9ZtFyhwygfjpH1 qRY6cvZgVDdzzGrtsGOOqKWhe0oswoEKE0yKEtgsaZtvHH3Jk+rG397yZXgJbRSgjrUk Y63w== X-Gm-Message-State: ACrzQf3vA7gQKkZXq69ULntMic9uW0/54EcXq0XBCDhHMBl5Rs8wu7BA W9IDDJmFt1W8kbNV8Gy0+Ig/UQ== X-Received: by 2002:a17:903:2307:b0:181:e618:b4c5 with SMTP id d7-20020a170903230700b00181e618b4c5mr33087193plh.172.1666632060401; Mon, 24 Oct 2022 10:21:00 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id i188-20020a626dc5000000b0056262811c5fsm72421pfc.59.2022.10.24.10.20.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Oct 2022 10:20:59 -0700 (PDT) From: Kees Cook To: "Darrick J . Wong" Cc: Kees Cook , Zorro Lang , linux-xfs@vger.kernel.org, "Gustavo A. R. Silva" , Keith Packard , Francis Laniel , Daniel Axtens , Dan Williams , Vincenzo Frascino , Guenter Roeck , Daniel Vetter , Tadeusz Struk , Geert Uytterhoeven , Andy Shevchenko , Paolo Abeni , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH 2/2] xfs: Use flex_cpy() to check extent copying Date: Mon, 24 Oct 2022 10:20:58 -0700 Message-Id: <20221024172058.534477-2-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221024171848.never.522-kees@kernel.org> References: <20221024171848.never.522-kees@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1465; h=from:subject; bh=x7Rm68JdcafZ41E9GsTynBW1VglPIkAcCBWjMgC1XZs=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBjVsl5e3fUqEVHLRTWTi07FP0i2KlufVIIqNEwvzK+ yPgcmKOJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCY1bJeQAKCRCJcvTf3G3AJpMWEA CCEj7newKc7qcVZhldSpFBK/EeIB9fXY4+iLuVdu3LFqPY13Hef3MaSmkB/Y4IRnNYMG1z40nYXPIX BRl9opcuI31xnN1rs9ZUql+0uHLhCbkvPekMurdx40/rXV8JSpfAawk6g/Hu4CzhhSEZPdV2BCmaA2 gPls9t3srVcaoPQcet6h5Vl878GD2tUPabyGLFzf2zrvkrYFuVG9Vcf8M6rzhWjAgTUrKXTOgGosnk yGdKK2sRbrNnAI3hLfunqyLQKTE2SM35KEak96gL9DDY4Yj+Jir7NkBast9okeDQfOYj3pfkyZyvVv yq3vnuORIfjZgdqMs/p+kv8pQKeOqwBTmplsuSM9xrTvOT1ElTE4P2+4hKNvRivsAlyme/BYPaUdW/ sUfyLqIoCWWsRNTtJ1BkJsPqnHMTxkelyCDmn5xTuYv+GAbx/2UG13vPbNvmJUPLxYTw+YeksRdUYl ZrMgfde6Ifb4yzbsuerEt/fkpd6/85Y7vJ4vf/GtZOdVt/QN4BDxlETGpas8pgV+Bs4tqMNFPpHRHm eFd8JmG9/qGYmtuaMepu/Rn7zhnwIYUevSDwoH+OanWEGdftSxXaQyEO28EEoMYEGbyWDTqkz04/4O zC5bLw/JhL8gPbVuJHIo7cu+CcKMc0HdtDfDGHW0LDUBdHrqREEUb2tKT8hw== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 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 Use flex_cpy() instead of memcpy() to copy the bui_fmt flexible array structure, which will perform bounds checking internally. Avoids the false positive warning seen under FORTIFY_SOURCE: memcpy: detected field-spanning write (size 48) of single field "dst_bui_fmt" at fs/xfs/xfs_bmap_item.c:628 (size 16) Reported-by: Zorro Lang Link: https://bugzilla.kernel.org/show_bug.cgi?id=216563 Cc: "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org Signed-off-by: Kees Cook --- fs/xfs/xfs_bmap_item.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/xfs/xfs_bmap_item.c b/fs/xfs/xfs_bmap_item.c index 51f66e982484..5f135893df66 100644 --- a/fs/xfs/xfs_bmap_item.c +++ b/fs/xfs/xfs_bmap_item.c @@ -24,6 +24,7 @@ #include "xfs_error.h" #include "xfs_log_priv.h" #include "xfs_log_recover.h" +#include struct kmem_cache *xfs_bui_cache; struct kmem_cache *xfs_bud_cache; @@ -624,10 +625,10 @@ xfs_bui_copy_format( src_bui_fmt = buf->i_addr; len = xfs_bui_log_format_sizeof(src_bui_fmt->bui_nextents); - if (buf->i_len == len) { - memcpy(dst_bui_fmt, src_bui_fmt, len); + if (buf->i_len == len && + __flex_cpy(dst_bui_fmt, src_bui_fmt, + bui_extents, bui_nextents, __passthru) == 0) return 0; - } XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, NULL); return -EFSCORRUPTED; } -- 2.34.1