diff mbox

[v2,1/2] coredump: use from_kuid/kgid when formatting corename

Message ID 1431656975-3563-1-git-send-email-nicolas.iooss_linux@m4x.org (mailing list archive)
State New, archived
Headers show

Commit Message

Nicolas Iooss May 15, 2015, 2:29 a.m. UTC
When adding __printf attribute to cn_printf, gcc reports some issues:

  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);
       ^

These warnings come from the fact that the value of uid/gid needs to be
extracted from the kuid_t/kgid_t structure before being used as an
integer.  More precisely, cred->uid and cred->gid need to be converted
to either user-namespace uid/gid or to init_user_ns uid/gid.

Use init_user_ns in order not to break existing ABI, and document this
in Documentation/sysctl/kernel.txt.

While at it, format uid and gid values with %u instead of %d because
uid_t/__kernel_uid32_t and gid_t/__kernel_gid32_t are unsigned int.

Signed-off-by: Nicolas Iooss <nicolas.iooss_linux@m4x.org>
---
 Documentation/sysctl/kernel.txt | 4 ++--
 fs/coredump.c                   | 8 ++++++--
 2 files changed, 8 insertions(+), 4 deletions(-)

Comments

Eric W. Biederman May 15, 2015, 2:52 p.m. UTC | #1
Nicolas Iooss <nicolas.iooss_linux@m4x.org> writes:

> When adding __printf attribute to cn_printf, gcc reports some issues:
>
>   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);
>        ^
>
> These warnings come from the fact that the value of uid/gid needs to be
> extracted from the kuid_t/kgid_t structure before being used as an
> integer.  More precisely, cred->uid and cred->gid need to be converted
> to either user-namespace uid/gid or to init_user_ns uid/gid.
>
> Use init_user_ns in order not to break existing ABI, and document this
> in Documentation/sysctl/kernel.txt.
>
> While at it, format uid and gid values with %u instead of %d because
> uid_t/__kernel_uid32_t and gid_t/__kernel_gid32_t are unsigned int.

Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>

> Signed-off-by: Nicolas Iooss <nicolas.iooss_linux@m4x.org>
> ---
>  Documentation/sysctl/kernel.txt | 4 ++--
>  fs/coredump.c                   | 8 ++++++--
>  2 files changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/Documentation/sysctl/kernel.txt b/Documentation/sysctl/kernel.txt
> index c831001c45f1..e1913f78f21e 100644
> --- a/Documentation/sysctl/kernel.txt
> +++ b/Documentation/sysctl/kernel.txt
> @@ -197,8 +197,8 @@ core_pattern is used to specify a core dumpfile pattern name.
>  	%P	global pid (init PID namespace)
>  	%i	tid
>  	%I	global tid (init PID namespace)
> -	%u	uid
> -	%g	gid
> +	%u	uid (in initial user namespace)
> +	%g	gid (in initial user namespace)
>  	%d	dump mode, matches PR_SET_DUMPABLE and
>  		/proc/sys/fs/suid_dumpable
>  	%s	signal number
> diff --git a/fs/coredump.c b/fs/coredump.c
> index bbbe139ab280..833a57bc856c 100644
> --- a/fs/coredump.c
> +++ b/fs/coredump.c
> @@ -209,11 +209,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, "%u",
> +						from_kuid(&init_user_ns,
> +							  cred->uid));
>  				break;
>  			/* gid */
>  			case 'g':
> -				err = cn_printf(cn, "%d", cred->gid);
> +				err = cn_printf(cn, "%u",
> +						from_kgid(&init_user_ns,
> +							  cred->gid));
>  				break;
>  			case 'd':
>  				err = cn_printf(cn, "%d",
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/Documentation/sysctl/kernel.txt b/Documentation/sysctl/kernel.txt
index c831001c45f1..e1913f78f21e 100644
--- a/Documentation/sysctl/kernel.txt
+++ b/Documentation/sysctl/kernel.txt
@@ -197,8 +197,8 @@  core_pattern is used to specify a core dumpfile pattern name.
 	%P	global pid (init PID namespace)
 	%i	tid
 	%I	global tid (init PID namespace)
-	%u	uid
-	%g	gid
+	%u	uid (in initial user namespace)
+	%g	gid (in initial user namespace)
 	%d	dump mode, matches PR_SET_DUMPABLE and
 		/proc/sys/fs/suid_dumpable
 	%s	signal number
diff --git a/fs/coredump.c b/fs/coredump.c
index bbbe139ab280..833a57bc856c 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -209,11 +209,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, "%u",
+						from_kuid(&init_user_ns,
+							  cred->uid));
 				break;
 			/* gid */
 			case 'g':
-				err = cn_printf(cn, "%d", cred->gid);
+				err = cn_printf(cn, "%u",
+						from_kgid(&init_user_ns,
+							  cred->gid));
 				break;
 			case 'd':
 				err = cn_printf(cn, "%d",