public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Eric Sandeen <sandeen@sandeen.net>
Cc: Eric Sandeen <sandeen@redhat.com>,
	linux-xfs <linux-xfs@vger.kernel.org>,
	Zorro Lang <zlang@redhat.com>
Subject: [PATCH] mkfs: fix symlink target if_bytes computation for protofile
Date: Tue, 11 Dec 2018 11:02:56 -0800	[thread overview]
Message-ID: <20181211190256.GV24487@magnolia> (raw)
In-Reply-To: <ca4c95cc-c8c5-c876-9ca4-a50794a4bb4f@sandeen.net>

From: Darrick J. Wong <darrick.wong@oracle.com>

When creating a local format symlink, we expect the target buffer in the
data fork to have enough space to contain the null, but we also expect
if_bytes to reflect the length of the target /not/ including the null.
If we don't adjust if_bytes down by one byte, we can run off into
uninitialized memory.  Fix this, which should clean up the spurious
xfs/019 failures for good.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 mkfs/proto.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/mkfs/proto.c b/mkfs/proto.c
index fc07de5f..dc0225bd 100644
--- a/mkfs/proto.c
+++ b/mkfs/proto.c
@@ -238,10 +238,18 @@ newfile(
 	flags = 0;
 	mp = ip->i_mount;
 	if (symlink && len <= XFS_IFORK_DSIZE(ip)) {
-		/* Copy the name's trailing NULL as well */
+		/*
+		 * Local format symbolic link targets are supposed to be NULL
+		 * terminated in memory.  This means that if_data must be at
+		 * least one byte longer than the target string's length so
+		 * that there's enough space to hold the null.  However, we
+		 * still expect if_bytes to be strlen(target), which does _not_
+		 * include the null.
+		 */
 		libxfs_idata_realloc(ip, len + 1, XFS_DATA_FORK);
 		if (buf)
 			memmove(ip->i_df.if_u1.if_data, buf, len + 1);
+		ip->i_df.if_bytes = len;
 		ip->i_d.di_size = len;
 		ip->i_df.if_flags &= ~XFS_IFEXTENTS;
 		ip->i_df.if_flags |= XFS_IFINLINE;

  parent reply	other threads:[~2018-12-11 19:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-26 22:39 [PATCH] mkfs.xfs: null-terminate symlinks created via protofile Eric Sandeen
2018-11-26 22:55 ` Darrick J. Wong
2018-11-26 23:01   ` Eric Sandeen
2018-11-26 23:04 ` [PATCH V2] " Eric Sandeen
2018-11-27 16:18   ` Darrick J. Wong
2018-12-11 19:02   ` Darrick J. Wong [this message]
2018-12-11 20:36     ` [PATCH] mkfs: fix symlink target if_bytes computation for protofile Eric Sandeen
2018-12-11 22:42       ` Darrick J. Wong
2018-12-12  4:50         ` Darrick J. Wong

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=20181211190256.GV24487@magnolia \
    --to=darrick.wong@oracle.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sandeen@redhat.com \
    --cc=sandeen@sandeen.net \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox