From: Kees Cook <kees@kernel.org>
To: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
Cc: Bill Wendling <morbo@google.com>,
"K. Y. Srinivasan" <kys@microsoft.com>,
Haiyang Zhang <haiyangz@microsoft.com>,
Wei Liu <wei.liu@kernel.org>, Dexuan Cui <decui@microsoft.com>,
Long Li <longli@microsoft.com>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Justin Stitt <justinstitt@google.com>,
linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org, llvm@lists.linux.dev,
codemender-patching+linux@google.com
Subject: Re: [PATCH] Drivers: hv: vmbus: annotate struct vmbus_gpadl with __counted_by_ptr
Date: Wed, 23 Sep 2026 00:23:01 -0700 [thread overview]
Message-ID: <202609230021.7F6F2140@keescook> (raw)
In-Reply-To: <a51283e0-7d55-4d06-bf7d-3cd7b7a21faa@embeddedor.com>
On Wed, Sep 23, 2026 at 03:10:08PM +0900, Gustavo A. R. Silva wrote:
>
>
> On 9/23/26 14:53, Bill Wendling wrote:
> > Add the "__counted_by_ptr" attribute to the buffer field of "struct
> > vmbus_gpadl". This allows compilers (GCC and Clang) to perform
> > compile-time and runtime bounds-checking when KASAN is enabled, preventing
> > potential out-of-bounds accesses to the GPADL buffer.
> >
> > The fields "buffer" and "size" of "struct vmbus_gpadl" are assigned
> > exactly once, during GPADL establishment inside
> > "__vmbus_establish_gpadl()" in "drivers/hv/channel.c".
> >
> > To ensure that the count field ("size") is initialized before the
> > pointer field ("buffer") is assigned, we reorder the assignments in
> > "__vmbus_establish_gpadl()" so that "gpadl->size" is written before
> > "gpadl->buffer".
> >
> > Cc: codemender-patching+linux@google.com
> > Assisted-by: LLM
> > Signed-off-by: Bill Wendling <morbo@google.com>
> > ---
> > drivers/hv/channel.c | 2 +-
> > include/linux/hyperv.h | 2 +-
> > 2 files changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
> > index 7e4cc6f55237..7042de2dd481 100644
> > --- a/drivers/hv/channel.c
> > +++ b/drivers/hv/channel.c
> > @@ -548,8 +548,8 @@ static int __vmbus_establish_gpadl(struct vmbus_channel *channel,
> > /* At this point, we received the gpadl created msg */
> > gpadl->gpadl_handle = gpadlmsg->gpadl;
> > - gpadl->buffer = kbuffer;
> > gpadl->size = size;
> > + gpadl->buffer = kbuffer;
>
> I think in some cases these subtle changes are worth a short but
> informative comment saying that the _counter_ must be initialized
> before the first reference to the pointer.
But that's only for dereferencing it... there's no ordering requirement
here at all (and I think swapping order is needless churn). Neither
order is correct: only having them both set before dereferencing
"buffer" is required.
--
Kees Cook
next prev parent reply other threads:[~2026-09-23 7:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-23 5:53 Bill Wendling
2026-09-23 6:10 ` Gustavo A. R. Silva
2026-09-23 7:23 ` Kees Cook [this message]
2026-09-23 8:02 ` Gustavo A. R. Silva
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=202609230021.7F6F2140@keescook \
--to=kees@kernel.org \
--cc=codemender-patching+linux@google.com \
--cc=decui@microsoft.com \
--cc=gustavo@embeddedor.com \
--cc=gustavoars@kernel.org \
--cc=haiyangz@microsoft.com \
--cc=justinstitt@google.com \
--cc=kys@microsoft.com \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=longli@microsoft.com \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=wei.liu@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®