coredump: fix cn_printf formatting warnings
PATCH 1/1 coredump: fix cn_printf formatting warnings
Add __printf attributes to cn_*printf functions. With these, gcc says:
fs/coredump.c:213:5: warning: format '%d' expects argument of type 'int', but argument 3 has type 'kuid_t' [-Wformat=]
err = cn_printf(cn, "%d", cred->uid);
^
fs/coredump.c:217:5: warning: format '%d' expects argument of type
'int', but argument 3 has type 'kgid_t' [-Wformat=]
err = cn_printf(cn, "%d", cred->gid);
^
fs/coredump.c:225:5: warning: format '%ld' expects argument of type
'long int', but argument 3 has type 'int' [-Wformat=]
err = cn_printf(cn, "%ld", cprm->siginfo->si_signo);
^The third warning is easily fixed as si_signo is always an int.
For the two others, cred->uid and cred->gid need to be converted to either a user-namespace UID/GID or to init_user_ns UID/GID. As Documentation/sysctl/kernel.txt does not specify which user namespace is used to translate %u and %g in core_pattern, but lowercase %p and %i are used to format pid/tid in current process namespace, it seems intuitive that lowercase %u and %g use the current user namespace. So implement this.
--- fs/coredump.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
fs/coredump.c +12 -6
@@ -70,7 +70,8 @@ static int expand_corename(struct core_name *cn, int size)return 0 ; } -static int cn_vprintf (struct core_name *cn,const char *fmt,va_list arg) +static __printf(2, 0) int cn_vprintf(struct core_name *cn, const char *fmt, +va_list arg) {int free, need;va_list arg_copy;
@@ -93,7 +94,7 @@ again:return -ENOMEM ; } -static int cn_printf (struct core_name *cn,const char *fmt, ...) +static __printf(2, 3) int cn_printf(struct core_name *cn, const char *fmt, ...) { va_list arg;int ret;
@@ -105,7 +106,8 @@ static int cn_printf(struct core_name *cn, const char *fmt, ...)return ret; } -static int cn_esc_printf (struct core_name *cn,const char *fmt, ...) +static __printf(2, 3) +int cn_esc_printf (struct core_name *cn,const char *fmt, ...) {int cur = cn->used;va_list arg;
@@ -209,11 +211,15 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)break ;/* uid */ case 'u' : - err =cn_printf (cn,"%d" , cred->uid); + err =cn_printf (cn,"%d" , +from_kuid_munged (cred->user_ns, + cred->uid));break ;/* gid */ case 'g' : - err =cn_printf (cn,"%d" , cred->gid); + err =cn_printf (cn,"%d" , +from_kgid_munged (cred->user_ns, + cred->gid));break ;case 'd' : err = cn_printf(cn, "%d",
@@ -221,7 +227,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)break ;/* signal that caused the coredump */ case 's' : - err =cn_printf (cn,"%ld" , cprm->siginfo->si_signo); + err =cn_printf (cn,"%d" , cprm->siginfo->si_signo);break ;/* UNIX time of coredump */ case 't' : {
Signature · 1 line
2.3.1
Ping? Comments (or NACK or ACK) would be greatly appreciated on this patch. Of course, if you prefer to use init_user_ns instead of cred->user_ns, I can send an other patch.
Nicolas
Quoted 91 lines · Nicolas Iooss
Add
__printfattributes to cn_*printf functions. With these, gcc says:
fs/coredump.c:213:5: warning: format '%d' expects argument of type 'int', but argument 3 has type 'kuid_t' [-Wformat=]err = cn_printf(cn, "%d", cred->uid); ^ fs/coredump.c:217:5: warning: format '%d' expects argument of type 'int', but argument 3 has type 'kgid_t' [-Wformat=] err = cn_printf(cn, "%d", cred->gid); ^ fs/coredump.c:225:5: warning: format '%ld' expects argument of type 'long int', but argument 3 has type 'int' [-Wformat=] err = cn_printf(cn, "%ld", cprm->siginfo->si_signo); ^The third warning is easily fixed as
si_signois always an int.For the two others,
cred->uidandcred->gidneed to be converted to either a user-namespace UID/GID or toinit_user_nsUID/GID. AsDocumentation/sysctl/kernel.txtdoes not specify which user namespace is used to translate %u and %g incore_pattern, but lowercase %p and %i are used to format pid/tid in current process namespace, it seems intuitive that lowercase %u and %g use the current user namespace. So implement this.Signed-off-by Nicolas Iooss <[email protected]>--- fs/coredump.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)fs/coredump.c +12
-6@@ -70,7 +70,8 @@ static int expand_corename(struct core_name *cn, int size)return 0 ; } -static int cn_vprintf (struct core_name *cn,const char *fmt,va_list arg) +static __printf(2, 0) int cn_vprintf(struct core_name *cn, const char *fmt, +va_list arg) {int free, need;va_list arg_copy;@@ -93,7 +94,7 @@ again:return -ENOMEM ; } -static int cn_printf (struct core_name *cn,const char *fmt, ...) +static __printf(2, 3) int cn_printf(struct core_name *cn, const char *fmt, ...) { va_list arg;int ret;@@ -105,7 +106,8 @@ static int cn_printf(struct core_name *cn, const char *fmt, ...)return ret; } -static int cn_esc_printf (struct core_name *cn,const char *fmt, ...) +static __printf(2, 3) +int cn_esc_printf (struct core_name *cn,const char *fmt, ...) {int cur = cn->used;va_list arg;@@ -209,11 +211,15 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)break ;/* uid */ case 'u' : - err =cn_printf (cn,"%d" , cred->uid); + err =cn_printf (cn,"%d" , +from_kuid_munged (cred->user_ns, + cred->uid));break ;/* gid */ case 'g' : - err =cn_printf (cn,"%d" , cred->gid); + err =cn_printf (cn,"%d" , +from_kgid_munged (cred->user_ns, + cred->gid));break ;case 'd' : err = cn_printf(cn, "%d",@@ -221,7 +227,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)break ;/* signal that caused the coredump */ case 's' : - err =cn_printf (cn,"%ld" , cprm->siginfo->si_signo); + err =cn_printf (cn,"%d" , cprm->siginfo->si_signo);break ;/* UNIX time of coredump */ case 't' : {