Linux Hardening
 help / color / mirror / Atom feed
From: John Johansen <john.johansen@canonical.com>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>,
	James Morris <jmorris@namei.org>,
	"Serge E. Hallyn" <serge@hallyn.com>
Cc: linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH][next] apparmor: Use struct_size() helper in kzalloc()
Date: Fri, 1 Oct 2021 16:37:08 -0700	[thread overview]
Message-ID: <4c851990-45d7-a0ff-e398-92ecb2454242@canonical.com> (raw)
In-Reply-To: <20210929220526.GA355783@embeddedor>

On 9/29/21 3:05 PM, Gustavo A. R. Silva wrote:
> Make use of the struct_size() helper instead of an open-coded version,
> in order to avoid any potential type mistakes or integer overflows that,
> in the worse scenario, could lead to heap overflows.
>> Link: https://github.com/KSPP/linux/issues/160
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>

nice

I will pull this into my tree
Acked-by: John Johansen <john.johansen@canonical.com>

> ---
>  security/apparmor/label.c  | 3 +--
>  security/apparmor/policy.c | 3 +--
>  2 files changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/security/apparmor/label.c b/security/apparmor/label.c
> index 6222fdfebe4e..0b0265da1926 100644
> --- a/security/apparmor/label.c
> +++ b/security/apparmor/label.c
> @@ -425,8 +425,7 @@ struct aa_label *aa_label_alloc(int size, struct aa_proxy *proxy, gfp_t gfp)
>  	AA_BUG(size < 1);
>  
>  	/*  + 1 for null terminator entry on vec */
> -	new = kzalloc(sizeof(*new) + sizeof(struct aa_profile *) * (size + 1),
> -			gfp);
> +	new = kzalloc(struct_size(new, vec, size + 1), gfp);
>  	AA_DEBUG("%s (%p)\n", __func__, new);
>  	if (!new)
>  		goto fail;
> diff --git a/security/apparmor/policy.c b/security/apparmor/policy.c
> index 17191a9eae41..5827dbdfbfca 100644
> --- a/security/apparmor/policy.c
> +++ b/security/apparmor/policy.c
> @@ -260,8 +260,7 @@ struct aa_profile *aa_alloc_profile(const char *hname, struct aa_proxy *proxy,
>  	struct aa_profile *profile;
>  
>  	/* freed by free_profile - usually through aa_put_profile */
> -	profile = kzalloc(sizeof(*profile) + sizeof(struct aa_profile *) * 2,
> -			  gfp);
> +	profile = kzalloc(struct_size(profile, label.vec, 2), gfp);
>  	if (!profile)
>  		return NULL;
>  
> 


  reply	other threads:[~2021-10-01 23:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-29 22:05 [PATCH][next] apparmor: Use struct_size() helper in kzalloc() Gustavo A. R. Silva
2021-10-01 23:37 ` John Johansen [this message]
2021-10-01 23:49   ` 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=4c851990-45d7-a0ff-e398-92ecb2454242@canonical.com \
    --to=john.johansen@canonical.com \
    --cc=gustavoars@kernel.org \
    --cc=jmorris@namei.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=serge@hallyn.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