From: Jan Beulich <jbeulich@suse.com>
To: Stephen Cheng <stephen.cheng@citrix.com>
Cc: andrew.cooper3@citrix.com, anthony.perard@vates.tech,
julien@xen.org, michal.orzel@amd.com, roger@xenproject.org,
sstabellini@kernel.org, xen-devel@lists.xenproject.org
Subject: Re: [PATCH v2] xmalloc: correct _xrealloc() for large or changing alignment
Date: Fri, 4 Dec 2026 09:11:39 +0100 [thread overview]
Message-ID: <2dfc3602-e4a0-423a-abcd-3ea95399cd33@suse.com> (raw)
In-Reply-To: <20261204025555.436959-1-stephen.cheng@citrix.com>
On 04.12.2026 03:55, Stephen Cheng wrote:
> On 03/12/2026 13:18, Jan Beulich wrote:
>> + if ( p != ptr )
>> + ptr = memmove(p, ptr, min(curr_size - (p - p0), size));
>
> Should this be min(curr_size - (ptr - p0), size), i.e. use the old
> padding, like the "curr_size -= ptr - p" below? With the new padding,
> when the pointer moves down and size is larger than the old data,
> memmove() reads past the end of the block. That is harmless in practice.
Upon looking more closely, I think the code is correct as-is. curr_size
describes the full block (from p0), and what we want to subtract is the
padding size that add_padding() inserts. The (possible) amount of
(original) tail padding doesn't matter. Whether we read into tail
padding isn't overly important, I think - maybe that you you meant with
"harmless". If we wanted to be more precise no matter whether size grows
or shrinks, I think it would need to be
min(curr_size - min(p - p0, ptr - p0)). Yet that extra complexity
doesn't look warranted.
Jan
next prev parent reply other threads:[~2026-12-04 8:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 13:17 [PATCH v2] xmalloc: correct _xrealloc() for large or changing alignment Jan Beulich
2026-12-04 2:55 ` Stephen Cheng
2026-12-04 6:42 ` Jan Beulich
2026-12-04 8:11 ` Jan Beulich [this message]
2026-12-04 9:03 ` Stephen Cheng
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=2dfc3602-e4a0-423a-abcd-3ea95399cd33@suse.com \
--to=jbeulich@suse.com \
--cc=andrew.cooper3@citrix.com \
--cc=anthony.perard@vates.tech \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=roger@xenproject.org \
--cc=sstabellini@kernel.org \
--cc=stephen.cheng@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/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.