public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@kernel.org>
To: Chandan Babu R <chandan.babu@oracle.com>,
	"Darrick J. Wong" <djwong@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>, kernel test robot <lkp@intel.com>,
	Dave Chinner <dchinner@redhat.com>,
	Kent Overstreet <kent.overstreet@linux.dev>,
	linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] xfs: trace: replace strncpy() with strscpy()
Date: Tue, 30 Jul 2024 17:16:26 +0200	[thread overview]
Message-ID: <20240730151716.2511975-1-arnd@kernel.org> (raw)

From: Arnd Bergmann <arnd@arndb.de>

I got a warning about an strncpy() with possibly missing NUL-termination:

In file included from include/trace/define_trace.h:102,
                 from fs/xfs/scrub/trace.h:3584,
                 from fs/xfs/scrub/trace.c:58:
fs/xfs/./scrub/trace.h: In function 'trace_event_raw_event_xfile_create':
fs/xfs/./scrub/trace.h:973:3: error: 'strncpy' specified bound 256 equals destination size [-Werror=stringop-truncation]

Use strscpy() to auto-size the output, and zero-pad the string
as before.

Reported-by: kernel test robot <lkp@intel.com>
Fixes: 3934e8ebb7cc ("xfs: create a big array data structure")
Closes: https://lore.kernel.org/oe-kbuild-all/202403290419.HPcyvqZu-lkp@intel.com/
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
I'm not entirely sure about whether to pad or not, as about half of the
ftrace macros with strscpy() pad and the other half don't. We probably
want them all to do the same thing here.

If there is a chance of leaking kernel stack data to userspace here,
we need to pad the string, otherwise not.
---
 fs/xfs/scrub/trace.h | 2 +-
 fs/xfs/xfs_trace.h   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/xfs/scrub/trace.h b/fs/xfs/scrub/trace.h
index 92ef4cdc486e..6f7fa24e1273 100644
--- a/fs/xfs/scrub/trace.h
+++ b/fs/xfs/scrub/trace.h
@@ -970,7 +970,7 @@ TRACE_EVENT(xfile_create,
 		path = file_path(xf->file, pathname, sizeof(pathname) - 1);
 		if (IS_ERR(path))
 			path = "(unknown)";
-		strncpy(__entry->pathname, path, sizeof(__entry->pathname));
+		strscpy_pad(__entry->pathname, path);
 	),
 	TP_printk("xfino 0x%lx path '%s'",
 		  __entry->ino,
diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h
index 5646d300b286..79d159fab2e6 100644
--- a/fs/xfs/xfs_trace.h
+++ b/fs/xfs/xfs_trace.h
@@ -4728,7 +4728,7 @@ TRACE_EVENT(xmbuf_create,
 		path = file_path(file, pathname, sizeof(pathname) - 1);
 		if (IS_ERR(path))
 			path = "(unknown)";
-		strncpy(__entry->pathname, path, sizeof(__entry->pathname));
+		strscpy_pad(__entry->pathname, path);
 	),
 	TP_printk("dev %d:%d xmino 0x%lx path '%s'",
 		  MAJOR(__entry->dev), MINOR(__entry->dev),
-- 
2.39.2


                 reply	other threads:[~2024-07-30 15:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20240730151716.2511975-1-arnd@kernel.org \
    --to=arnd@kernel.org \
    --cc=arnd@arndb.de \
    --cc=chandan.babu@oracle.com \
    --cc=dchinner@redhat.com \
    --cc=djwong@kernel.org \
    --cc=kent.overstreet@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=lkp@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox