From patchwork Sun May 3 10:34:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Iooss X-Patchwork-Id: 6320751 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9AE6CBEEE1 for ; Sun, 3 May 2015 10:37:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BE5A9203AF for ; Sun, 3 May 2015 10:37:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E872F203B8 for ; Sun, 3 May 2015 10:37:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751917AbbECKgq (ORCPT ); Sun, 3 May 2015 06:36:46 -0400 Received: from mx1.polytechnique.org ([129.104.30.34]:49391 "EHLO mx1.polytechnique.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751359AbbECKgp (ORCPT ); Sun, 3 May 2015 06:36:45 -0400 Received: from iosakhe.localdomain (unknown [103.252.202.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by ssl.polytechnique.org (Postfix) with ESMTPSA id A7FF81408EFA7; Sun, 3 May 2015 12:36:41 +0200 (CEST) From: Nicolas Iooss To: Alexander Viro , linux-fsdevel@vger.kernel.org Cc: Andrew Morton , linux-kernel@vger.kernel.org, Nicolas Iooss Subject: [PATCH 1/2] coredump: use from_kuid/kgid_munged when formatting corename Date: Sun, 3 May 2015 18:34:05 +0800 Message-Id: <1430649246-32726-1-git-send-email-nicolas.iooss_linux@m4x.org> X-Mailer: git-send-email 2.3.6 In-Reply-To: <1429181404.2850.44.camel@perches.com> References: <1429181404.2850.44.camel@perches.com> X-AV-Checked: ClamAV using ClamSMTP at svoboda.polytechnique.org (Sun May 3 12:36:43 2015 +0200 (CEST)) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. 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 the current process namespace, it seems intuitive that lowercase %u and %g use the current user namespace. 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 --- fs/coredump.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/coredump.c b/fs/coredump.c index bbbe139ab280..99c8af640c5a 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_munged(cred->user_ns, + cred->uid)); break; /* gid */ case 'g': - err = cn_printf(cn, "%d", cred->gid); + err = cn_printf(cn, "%u", + from_kgid_munged(cred->user_ns, + cred->gid)); break; case 'd': err = cn_printf(cn, "%d",