Format specifier issue when building kernel

Richard Guy Briggs rgb at redhat.com
Thu Oct 31 18:45:24 UTC 2013


On Mon, Oct 28, 2013 at 08:55:08PM -0700, William Roberts wrote:
> On Mon, Oct 28, 2013 at 6:43 PM, William Roberts
> <bill.c.roberts at gmail.com>wrote:
> > On Mon, Oct 28, 2013 at 6:35 PM, Richard Guy Briggs <rgb at redhat.com>wrote:
> >> On Mon, Oct 28, 2013 at 04:31:30PM -0700, William Roberts wrote:
> >> > On Mon, Oct 28, 2013 at 4:30 PM, William Roberts
> >> > <bill.c.roberts at gmail.com>wrote:
> >> > > I've been working off of Richard Guy Brigs git repo on branch
> >> > > audit-for-next prepping my patch and I noticed a build warning:
> >> > >
> >> > > kernel/audit.c:832:8: warning: format ‘%A’ expects argument of type
> >> > > ‘double’, but argument 3 has type ‘char *’ [-Wformat]
> >> > >
> >> > > Looking at the code, it looks wrong:
> >> > >
> >> > >                                 audit_log_format(ab,
> >> >                                                  "
> >> > msg='%.AUDIT_MESSAGE_TEXT_MAXs'",
> >> >                                                  (char *)data);
> >> >
> >> > The issue appears on the % specifier in there, it picks it up as
> >> > %.A, which is of type double. Is this what was intended?
> >>
> >> Hmmm, that should have picked up a macro from 06051fbe in
> >> audit-for-next.  It should be pre-processed to "%.8560s".
> >>
> >> > William C Roberts
> >>
> >> - RGB
> >
> > The qoutes are wrong for that.
> 
> Ok I see the value is not a string, but a numeric constant. Dont you need
> to do something like this:
> diff --git a/kernel/audit.c b/kernel/audit.c
> index bf4b1af..81dde3d 100644
> --- a/kernel/audit.c
> +++ b/kernel/audit.c
> @@ -825,10 +825,12 @@ static int audit_receive_msg(struct sk_buff *skb,
> struct nlmsghdr *nlh)
>                                 if (err)
>                                         break;
>                         }
> +#define STR_HELPER(x) #x
> +#define STR(x) STR_HELPER(x)
>                         audit_log_common_recv_msg(&ab, msg_type);
>                         if (msg_type != AUDIT_USER_TTY)
>                                 audit_log_format(ab,
> -                                                "
> msg='%.AUDIT_MESSAGE_TEXT_MAXs'",
> +                                                "
> msg='%."STR(AUDIT_MESSAGE_TEXT_MAX)"s'",
>                                                  (char *)data);
>                         else {
>                                 int size;

Ugh.  That's not so easy to read...  Slightly longer, how about this?

diff --git a/kernel/audit.c b/kernel/audit.c
index 8378c5e..3f569d1 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -824,11 +824,13 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
 					break;
 			}
 			audit_log_common_recv_msg(&ab, msg_type);
-			if (msg_type != AUDIT_USER_TTY)
-				audit_log_format(ab,
-						 " msg='%.AUDIT_MESSAGE_TEXT_MAXs'",
-						 (char *)data);
-			else {
+			if (msg_type != AUDIT_USER_TTY) {
+				char fmt[64];
+				strcat(fmt, " msg='%.");
+				strcat(fmt, "AUDIT_MESSAGE_TEXT_MAX");
+				strcat(fmt, "s'");
+				audit_log_format(ab, fmt, (char *)data);
+			} else {
 				int size;
 
 				audit_log_format(ab, " data=");

> Unless their is some gnu-magic I don't know about.
> 
> William C Roberts

- RGB

--
Richard Guy Briggs <rbriggs at redhat.com>
Senior Software Engineer
Kernel Security
AMER ENG Base Operating Systems
Remote, Ottawa, Canada
Voice: +1.647.777.2635
Internal: (81) 32635
Alt: +1.613.693.0684x3545




More information about the Linux-audit mailing list