linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] integrity: check the return value of audit_log_start()
@ 2021-12-14  3:34 xkernel.wang
  2022-01-12 17:23 ` Paul Moore
  0 siblings, 1 reply; 3+ messages in thread
From: xkernel.wang @ 2021-12-14  3:34 UTC (permalink / raw)
  To: jmorris, serge; +Cc: linux-security-module, linux-kernel, Xiaoke Wang

From: Xiaoke Wang <xkernel.wang@foxmail.com>

audit_log_start() returns audit_buffer pointer on success or NULL on
error, so it is better to check the return value of it to prevent
potential memory access error.

Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
---
 security/integrity/integrity_audit.c | 38 +++++++++++++++-------------
 1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/security/integrity/integrity_audit.c b/security/integrity/integrity_audit.c
index 2922005..62785d5 100644
--- a/security/integrity/integrity_audit.c
+++ b/security/integrity/integrity_audit.c
@@ -45,23 +45,25 @@ void integrity_audit_message(int audit_msgno, struct inode *inode,
 		return;
 
 	ab = audit_log_start(audit_context(), GFP_KERNEL, audit_msgno);
-	audit_log_format(ab, "pid=%d uid=%u auid=%u ses=%u",
-			 task_pid_nr(current),
-			 from_kuid(&init_user_ns, current_uid()),
-			 from_kuid(&init_user_ns, audit_get_loginuid(current)),
-			 audit_get_sessionid(current));
-	audit_log_task_context(ab);
-	audit_log_format(ab, " op=%s cause=%s comm=", op, cause);
-	audit_log_untrustedstring(ab, get_task_comm(name, current));
-	if (fname) {
-		audit_log_format(ab, " name=");
-		audit_log_untrustedstring(ab, fname);
+	if (ab) {
+		audit_log_format(ab, "pid=%d uid=%u auid=%u ses=%u",
+				task_pid_nr(current),
+				from_kuid(&init_user_ns, current_uid()),
+				from_kuid(&init_user_ns, audit_get_loginuid(current)),
+				audit_get_sessionid(current));
+		audit_log_task_context(ab);
+		audit_log_format(ab, " op=%s cause=%s comm=", op, cause);
+		audit_log_untrustedstring(ab, get_task_comm(name, current));
+		if (fname) {
+			audit_log_format(ab, " name=");
+			audit_log_untrustedstring(ab, fname);
+		}
+		if (inode) {
+			audit_log_format(ab, " dev=");
+			audit_log_untrustedstring(ab, inode->i_sb->s_id);
+			audit_log_format(ab, " ino=%lu", inode->i_ino);
+		}
+		audit_log_format(ab, " res=%d errno=%d", !result, errno);
+		audit_log_end(ab);
 	}
-	if (inode) {
-		audit_log_format(ab, " dev=");
-		audit_log_untrustedstring(ab, inode->i_sb->s_id);
-		audit_log_format(ab, " ino=%lu", inode->i_ino);
-	}
-	audit_log_format(ab, " res=%d errno=%d", !result, errno);
-	audit_log_end(ab);
 }
-- 

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

* Re: [PATCH] integrity: check the return value of audit_log_start()
  2021-12-14  3:34 [PATCH] integrity: check the return value of audit_log_start() xkernel.wang
@ 2022-01-12 17:23 ` Paul Moore
  2022-01-17 22:58   ` Mimi Zohar
  0 siblings, 1 reply; 3+ messages in thread
From: Paul Moore @ 2022-01-12 17:23 UTC (permalink / raw)
  To: xkernel.wang; +Cc: jmorris, serge, linux-security-module, linux-kernel

On Tue, Dec 14, 2021 at 12:39 AM <xkernel.wang@foxmail.com> wrote:
>
> From: Xiaoke Wang <xkernel.wang@foxmail.com>
>
> audit_log_start() returns audit_buffer pointer on success or NULL on
> error, so it is better to check the return value of it to prevent
> potential memory access error.
>
> Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
> ---
>  security/integrity/integrity_audit.c | 38 +++++++++++++++-------------
>  1 file changed, 20 insertions(+), 18 deletions(-)
>
> diff --git a/security/integrity/integrity_audit.c b/security/integrity/integrity_audit.c
> index 2922005..62785d5 100644
> --- a/security/integrity/integrity_audit.c
> +++ b/security/integrity/integrity_audit.c
> @@ -45,23 +45,25 @@ void integrity_audit_message(int audit_msgno, struct inode *inode,
>                 return;
>
>         ab = audit_log_start(audit_context(), GFP_KERNEL, audit_msgno);

As this is IMA code, it's largely up to Mimi about what she would
prefer, but I think a much simpler patch would be to just return early
if ab == NULL, for example:

  ab = audit_log_start( .... , audit_msgno);
  if (!ab)
    return;

> -       audit_log_format(ab, "pid=%d uid=%u auid=%u ses=%u",
> -                        task_pid_nr(current),
> -                        from_kuid(&init_user_ns, current_uid()),
> -                        from_kuid(&init_user_ns, audit_get_loginuid(current)),
> -                        audit_get_sessionid(current));
> -       audit_log_task_context(ab);
> -       audit_log_format(ab, " op=%s cause=%s comm=", op, cause);
> -       audit_log_untrustedstring(ab, get_task_comm(name, current));
> -       if (fname) {
> -               audit_log_format(ab, " name=");
> -               audit_log_untrustedstring(ab, fname);
> +       if (ab) {
> +               audit_log_format(ab, "pid=%d uid=%u auid=%u ses=%u",
> +                               task_pid_nr(current),
> +                               from_kuid(&init_user_ns, current_uid()),
> +                               from_kuid(&init_user_ns, audit_get_loginuid(current)),
> +                               audit_get_sessionid(current));
> +               audit_log_task_context(ab);
> +               audit_log_format(ab, " op=%s cause=%s comm=", op, cause);
> +               audit_log_untrustedstring(ab, get_task_comm(name, current));
> +               if (fname) {
> +                       audit_log_format(ab, " name=");
> +                       audit_log_untrustedstring(ab, fname);
> +               }
> +               if (inode) {
> +                       audit_log_format(ab, " dev=");
> +                       audit_log_untrustedstring(ab, inode->i_sb->s_id);
> +                       audit_log_format(ab, " ino=%lu", inode->i_ino);
> +               }
> +               audit_log_format(ab, " res=%d errno=%d", !result, errno);
> +               audit_log_end(ab);
>         }
> -       if (inode) {
> -               audit_log_format(ab, " dev=");
> -               audit_log_untrustedstring(ab, inode->i_sb->s_id);
> -               audit_log_format(ab, " ino=%lu", inode->i_ino);
> -       }
> -       audit_log_format(ab, " res=%d errno=%d", !result, errno);
> -       audit_log_end(ab);
>  }
> --



-- 
paul moore
www.paul-moore.com

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

* Re: [PATCH] integrity: check the return value of audit_log_start()
  2022-01-12 17:23 ` Paul Moore
@ 2022-01-17 22:58   ` Mimi Zohar
  0 siblings, 0 replies; 3+ messages in thread
From: Mimi Zohar @ 2022-01-17 22:58 UTC (permalink / raw)
  To: Paul Moore, xkernel.wang
  Cc: jmorris, serge, linux-security-module, linux-kernel

On Wed, 2022-01-12 at 12:23 -0500, Paul Moore wrote:
> On Tue, Dec 14, 2021 at 12:39 AM <xkernel.wang@foxmail.com> wrote:
> >
> > From: Xiaoke Wang <xkernel.wang@foxmail.com>
> >
> > audit_log_start() returns audit_buffer pointer on success or NULL on
> > error, so it is better to check the return value of it to prevent
> > potential memory access error.
> >
> > Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
> > ---
> >  security/integrity/integrity_audit.c | 38 +++++++++++++++-------------
> >  1 file changed, 20 insertions(+), 18 deletions(-)
> >
> > diff --git a/security/integrity/integrity_audit.c b/security/integrity/integrity_audit.c
> > index 2922005..62785d5 100644
> > --- a/security/integrity/integrity_audit.c
> > +++ b/security/integrity/integrity_audit.c
> > @@ -45,23 +45,25 @@ void integrity_audit_message(int audit_msgno, struct inode *inode,
> >                 return;
> >
> >         ab = audit_log_start(audit_context(), GFP_KERNEL, audit_msgno);
> 
> As this is IMA code, it's largely up to Mimi about what she would
> prefer, but I think a much simpler patch would be to just return early
> if ab == NULL, for example:
> 
>   ab = audit_log_start( .... , audit_msgno);
>   if (!ab)
>     return;

Thanks, Paul.  Neither the linux-integrity mailing list nor I were
Cc'ed on this.  Looks like the IMA & EVM records in MAINTAINERS should
be updated to include the security/integrity directory.

thanks,

Mimi


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

end of thread, other threads:[~2022-01-17 22:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-14  3:34 [PATCH] integrity: check the return value of audit_log_start() xkernel.wang
2022-01-12 17:23 ` Paul Moore
2022-01-17 22:58   ` Mimi Zohar

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).