linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] apparmor: fix error check
@ 2020-10-04 14:24 trix
  2020-12-21 19:22 ` Nick Desaulniers
  2021-02-07 11:27 ` John Johansen
  0 siblings, 2 replies; 3+ messages in thread
From: trix @ 2020-10-04 14:24 UTC (permalink / raw)
  To: john.johansen, jmorris, serge, natechancellor, ndesaulniers
  Cc: linux-security-module, linux-kernel, clang-built-linux, Tom Rix

From: Tom Rix <trix@redhat.com>

clang static analysis reports this representative problem:

label.c:1463:16: warning: Assigned value is garbage or undefined
        label->hname = name;
                     ^ ~~~~

In aa_update_label_name(), this the problem block of code

	if (aa_label_acntsxprint(&name, ...) == -1)
		return res;

On failure, aa_label_acntsxprint() has a more complicated return
that just -1.  So check for a negative return.

It was also noted that the aa_label_acntsxprint() main comment refers
to a nonexistent parameter, so clean up the comment.

Fixes: f1bd904175e8 ("apparmor: add the base fns() for domain labels")
Signed-off-by: Tom Rix <trix@redhat.com>
---
 security/apparmor/label.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/security/apparmor/label.c b/security/apparmor/label.c
index e68bcedca976..6222fdfebe4e 100644
--- a/security/apparmor/label.c
+++ b/security/apparmor/label.c
@@ -1454,7 +1454,7 @@ bool aa_update_label_name(struct aa_ns *ns, struct aa_label *label, gfp_t gfp)
 	if (label->hname || labels_ns(label) != ns)
 		return res;
 
-	if (aa_label_acntsxprint(&name, ns, label, FLAGS_NONE, gfp) == -1)
+	if (aa_label_acntsxprint(&name, ns, label, FLAGS_NONE, gfp) < 0)
 		return res;
 
 	ls = labels_set(label);
@@ -1704,7 +1704,7 @@ int aa_label_asxprint(char **strp, struct aa_ns *ns, struct aa_label *label,
 
 /**
  * aa_label_acntsxprint - allocate a __counted string buffer and print label
- * @strp: buffer to write to. (MAY BE NULL if @size == 0)
+ * @strp: buffer to write to.
  * @ns: namespace profile is being viewed from
  * @label: label to view (NOT NULL)
  * @flags: flags controlling what label info is printed
-- 
2.18.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] apparmor: fix error check
  2020-10-04 14:24 [PATCH] apparmor: fix error check trix
@ 2020-12-21 19:22 ` Nick Desaulniers
  2021-02-07 11:27 ` John Johansen
  1 sibling, 0 replies; 3+ messages in thread
From: Nick Desaulniers @ 2020-12-21 19:22 UTC (permalink / raw)
  To: Tom Rix
  Cc: john.johansen, James Morris, Serge E. Hallyn, Nathan Chancellor,
	linux-security-module, LKML, clang-built-linux

On Sun, Oct 4, 2020 at 7:24 AM <trix@redhat.com> wrote:
>
> From: Tom Rix <trix@redhat.com>
>
> clang static analysis reports this representative problem:
>
> label.c:1463:16: warning: Assigned value is garbage or undefined
>         label->hname = name;
>                      ^ ~~~~

Right, so if aa_label_acntsxprint() fails, it won't assign to its
first param. In the caller, this means assigning uninitialized memory
(UB) when aa_label_acntsxprint() returns -ENOMEM for example.  Thanks
for the patch.

Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

>
> In aa_update_label_name(), this the problem block of code
>
>         if (aa_label_acntsxprint(&name, ...) == -1)
>                 return res;
>
> On failure, aa_label_acntsxprint() has a more complicated return
> that just -1.  So check for a negative return.
>
> It was also noted that the aa_label_acntsxprint() main comment refers
> to a nonexistent parameter, so clean up the comment.
>
> Fixes: f1bd904175e8 ("apparmor: add the base fns() for domain labels")
> Signed-off-by: Tom Rix <trix@redhat.com>
> ---
>  security/apparmor/label.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/security/apparmor/label.c b/security/apparmor/label.c
> index e68bcedca976..6222fdfebe4e 100644
> --- a/security/apparmor/label.c
> +++ b/security/apparmor/label.c
> @@ -1454,7 +1454,7 @@ bool aa_update_label_name(struct aa_ns *ns, struct aa_label *label, gfp_t gfp)
>         if (label->hname || labels_ns(label) != ns)
>                 return res;
>
> -       if (aa_label_acntsxprint(&name, ns, label, FLAGS_NONE, gfp) == -1)
> +       if (aa_label_acntsxprint(&name, ns, label, FLAGS_NONE, gfp) < 0)
>                 return res;
>
>         ls = labels_set(label);
> @@ -1704,7 +1704,7 @@ int aa_label_asxprint(char **strp, struct aa_ns *ns, struct aa_label *label,
>
>  /**
>   * aa_label_acntsxprint - allocate a __counted string buffer and print label
> - * @strp: buffer to write to. (MAY BE NULL if @size == 0)
> + * @strp: buffer to write to.
>   * @ns: namespace profile is being viewed from
>   * @label: label to view (NOT NULL)
>   * @flags: flags controlling what label info is printed
> --
> 2.18.1
>
> --
> You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to clang-built-linux+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20201004142422.5717-1-trix%40redhat.com.



-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] apparmor: fix error check
  2020-10-04 14:24 [PATCH] apparmor: fix error check trix
  2020-12-21 19:22 ` Nick Desaulniers
@ 2021-02-07 11:27 ` John Johansen
  1 sibling, 0 replies; 3+ messages in thread
From: John Johansen @ 2021-02-07 11:27 UTC (permalink / raw)
  To: trix, jmorris, serge, natechancellor, ndesaulniers
  Cc: linux-security-module, linux-kernel, clang-built-linux

On 10/4/20 7:24 AM, trix@redhat.com wrote:
> From: Tom Rix <trix@redhat.com>
> 
> clang static analysis reports this representative problem:
> 
> label.c:1463:16: warning: Assigned value is garbage or undefined
>         label->hname = name;
>                      ^ ~~~~
> 
> In aa_update_label_name(), this the problem block of code
> 
> 	if (aa_label_acntsxprint(&name, ...) == -1)
> 		return res;
> 
> On failure, aa_label_acntsxprint() has a more complicated return
> that just -1.  So check for a negative return.
> 
> It was also noted that the aa_label_acntsxprint() main comment refers
> to a nonexistent parameter, so clean up the comment.
> 
> Fixes: f1bd904175e8 ("apparmor: add the base fns() for domain labels")
> Signed-off-by: Tom Rix <trix@redhat.com>
> ---
>  security/apparmor/label.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/security/apparmor/label.c b/security/apparmor/label.c
> index e68bcedca976..6222fdfebe4e 100644
> --- a/security/apparmor/label.c
> +++ b/security/apparmor/label.c
> @@ -1454,7 +1454,7 @@ bool aa_update_label_name(struct aa_ns *ns, struct aa_label *label, gfp_t gfp)
>  	if (label->hname || labels_ns(label) != ns)
>  		return res;
>  
> -	if (aa_label_acntsxprint(&name, ns, label, FLAGS_NONE, gfp) == -1)
> +	if (aa_label_acntsxprint(&name, ns, label, FLAGS_NONE, gfp) < 0)
>  		return res;
>  
>  	ls = labels_set(label);
> @@ -1704,7 +1704,7 @@ int aa_label_asxprint(char **strp, struct aa_ns *ns, struct aa_label *label,
>  
>  /**
>   * aa_label_acntsxprint - allocate a __counted string buffer and print label
> - * @strp: buffer to write to. (MAY BE NULL if @size == 0)
> + * @strp: buffer to write to.
>   * @ns: namespace profile is being viewed from
>   * @label: label to view (NOT NULL)
>   * @flags: flags controlling what label info is printed
> 


sorry it seems I missed replying to this. This patch has been pulled into apparmor-next

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-02-07 11:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-04 14:24 [PATCH] apparmor: fix error check trix
2020-12-21 19:22 ` Nick Desaulniers
2021-02-07 11:27 ` John Johansen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).