public inbox for llvm@lists.linux.dev
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: Bryan Tan <bryantan@vmware.com>, Vishnu Dasa <vdasa@vmware.com>,
	VMware PV-Drivers Reviewers <pv-drivers@vmware.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Tom Rix <trix@redhat.com>,
	linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org,
	linux-hardening@vger.kernel.org, llvm@lists.linux.dev
Subject: Re: [PATCH] VMCI: Annotate struct vmci_handle_arr with __counted_by
Date: Sun, 8 Oct 2023 10:12:01 -0700	[thread overview]
Message-ID: <202310081009.045F3E99@keescook> (raw)
In-Reply-To: <56bef519d982218176b59bbba64a3a308d8733d5.1696689091.git.christophe.jaillet@wanadoo.fr>

On Sat, Oct 07, 2023 at 04:32:34PM +0200, Christophe JAILLET wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> This patch is part of a work done in parallel of what is currently worked
> on by Kees Cook.
> 
> My patches are only related to corner cases that do NOT match the
> semantic of his Coccinelle script[1].
> 
> In this case, something similar to struct_size() is implemented in
> handle_arr_calc_size().

I think this should likely lose VMCI_HANDLE_ARRAY_HEADER_SIZE entirely
and the helper to use sizeof() and struct_size() directly, but probably
as a separate patch.

> 
> Note that I'm slightly unsure on how things will behave in regards to the
> krealloc() in vmci_handle_arr_append_entry().

It looks correct to me:

                new_array = krealloc(array, new_size, GFP_ATOMIC);
		...
                new_array->capacity += capacity_bump;

i.e. "capacity" is adjusted up before accessing any "entries".

> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> ---
>  drivers/misc/vmw_vmci/vmci_handle_array.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/misc/vmw_vmci/vmci_handle_array.h b/drivers/misc/vmw_vmci/vmci_handle_array.h
> index 96193f85be5b..b0e6b1956014 100644
> --- a/drivers/misc/vmw_vmci/vmci_handle_array.h
> +++ b/drivers/misc/vmw_vmci/vmci_handle_array.h
> @@ -17,7 +17,7 @@ struct vmci_handle_arr {
>  	u32 max_capacity;
>  	u32 size;
>  	u32 pad;
> -	struct vmci_handle entries[];
> +	struct vmci_handle entries[] __counted_by(capacity);
>  };
>  
>  #define VMCI_HANDLE_ARRAY_HEADER_SIZE				\
> -- 
> 2.34.1
> 

Reviewed-by: Kees Cook <keescook@chromium.org>


-- 
Kees Cook

  reply	other threads:[~2023-10-08 17:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-07 14:32 [PATCH] VMCI: Annotate struct vmci_handle_arr with __counted_by Christophe JAILLET
2023-10-08 17:12 ` Kees Cook [this message]
2023-11-30 22:00 ` Kees Cook

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=202310081009.045F3E99@keescook \
    --to=keescook@chromium.org \
    --cc=arnd@arndb.de \
    --cc=bryantan@vmware.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=gregkh@linuxfoundation.org \
    --cc=gustavoars@kernel.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=pv-drivers@vmware.com \
    --cc=trix@redhat.com \
    --cc=vdasa@vmware.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