From: Kees Cook <keescook@chromium.org>
To: "Darrick J . Wong" <djwong@kernel.org>
Cc: Kees Cook <keescook@chromium.org>, Zorro Lang <zlang@redhat.com>,
linux-xfs@vger.kernel.org,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
Keith Packard <keithp@keithp.com>,
Francis Laniel <laniel_francis@privacyrequired.com>,
Daniel Axtens <dja@axtens.net>,
Dan Williams <dan.j.williams@intel.com>,
Vincenzo Frascino <vincenzo.frascino@arm.com>,
Guenter Roeck <linux@roeck-us.net>,
Daniel Vetter <daniel.vetter@ffwll.ch>,
Tadeusz Struk <tadeusz.struk@linaro.org>,
Geert Uytterhoeven <geert@linux-m68k.org>,
Andy Shevchenko <andriy.shevchenko@intel.com>,
Paolo Abeni <pabeni@redhat.com>,
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 [thread overview]
Message-ID: <20221024172058.534477-2-keescook@chromium.org> (raw)
In-Reply-To: <20221024171848.never.522-kees@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 <zlang@redhat.com>
Link: https://bugzilla.kernel.org/show_bug.cgi?id=216563
Cc: "Darrick J. Wong" <djwong@kernel.org>
Cc: linux-xfs@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
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 <linux/flex_array.h>
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
next prev parent reply other threads:[~2022-10-24 18:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-24 17:20 [PATCH v2 0/2] Introduce flexible array struct helpers Kees Cook
2022-10-24 17:20 ` [PATCH v2 1/2] " Kees Cook
2022-10-24 18:35 ` Keith Packard
2022-10-26 20:33 ` Kees Cook
2022-10-25 6:12 ` kernel test robot
2022-10-25 8:57 ` Andy Shevchenko
2022-10-24 17:20 ` Kees Cook [this message]
2022-10-25 8:58 ` [PATCH 2/2] xfs: Use flex_cpy() to check extent copying Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221024172058.534477-2-keescook@chromium.org \
--to=keescook@chromium.org \
--cc=andriy.shevchenko@intel.com \
--cc=dan.j.williams@intel.com \
--cc=daniel.vetter@ffwll.ch \
--cc=dja@axtens.net \
--cc=djwong@kernel.org \
--cc=geert@linux-m68k.org \
--cc=gustavoars@kernel.org \
--cc=keithp@keithp.com \
--cc=laniel_francis@privacyrequired.com \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=pabeni@redhat.com \
--cc=tadeusz.struk@linaro.org \
--cc=vincenzo.frascino@arm.com \
--cc=zlang@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.