From: Dave Chinner <david@fromorbit.com>
To: Eric Sandeen <sandeen@redhat.com>
Cc: xfs@oss.sgi.com
Subject: Re: [PATCH] xfs: avoid null *src in memcpy call in xlog_write
Date: Thu, 8 Oct 2015 08:24:22 +1100 [thread overview]
Message-ID: <20151007212422.GS27164@dastard> (raw)
In-Reply-To: <56154967.70100@redhat.com>
On Wed, Oct 07, 2015 at 11:33:43AM -0500, Eric Sandeen wrote:
> The gcc undefined behavior sanitizer caught this; surely
> any sane memcpy implementation will no-op if size == 0,
> but behavior with a *src of NULL is technically undefined
> (declared nonnull), so avoid it here.
>
> We are actually in this situation frequently via
> xlog_commit_record(), because:
>
> struct xfs_log_iovec reg = {
> .i_addr = NULL,
> .i_len = 0,
> .i_type = XLOG_REG_TYPE_COMMIT,
> };
>
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---
>
> diff --git a/fs/xfs/xfs_log.c b/fs/xfs/xfs_log.c
> index 4012523..8897fd1 100644
> --- a/fs/xfs/xfs_log.c
> +++ b/fs/xfs/xfs_log.c
> @@ -2424,7 +2424,10 @@ xlog_write(
>
> /* copy region */
> ASSERT(copy_len >= 0);
> - memcpy(ptr, reg->i_addr + copy_off, copy_len);
> + ASSERT(reg->i_addr + copy_off > 0 || copy_len == 0);
> + /* size == 0 is ok, but *src == NULL is undefined */
> + if (reg->i_addr + copy_off)
> + memcpy(ptr, reg->i_addr + copy_off, copy_len);
> xlog_write_adv_cnt(&ptr, &len, &log_offset, copy_len);
The comment doesn't explain anything about why copylen might be zero
or reg->i_addr might be null. If copylen is zero, we should really
skip the copy, not rely on some magic pointer arithmetic to tell us
it's ok to copy...
/*
* Copy region.
*
* Unmount records just log an opheader, so can have
* empty payloads with no data region to copy. Hence we only
* copy the payload if the vector says it has data to copy.
*/
ASSERT(copy_len >= 0);
if (copy_len > 0) {
memcpy(ptr, reg->i_addr + copy_off, copy_len);
xlog_write_adv_cnt(&ptr, &len, &log_offset, copy_len);
}
Cheers,
Dave.
--
Dave Chinner
david@fromorbit.com
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
next prev parent reply other threads:[~2015-10-07 21:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-07 16:33 [PATCH] xfs: avoid null *src in memcpy call in xlog_write Eric Sandeen
2015-10-07 16:48 ` Bill O'Donnell
2015-10-07 21:24 ` Dave Chinner [this message]
2015-10-07 21:31 ` Eric Sandeen
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=20151007212422.GS27164@dastard \
--to=david@fromorbit.com \
--cc=sandeen@redhat.com \
--cc=xfs@oss.sgi.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.