lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210715031533.9553-9-justin.he@arm.com>
Date:   Thu, 15 Jul 2021 11:15:28 +0800
From:   Jia He <justin.he@....com>
To:     linux-kernel@...r.kernel.org
Cc:     Linus Torvalds <torvalds@...ux-foundation.org>,
        Christoph Hellwig <hch@...radead.org>, nd@....com,
        Jia He <justin.he@....com>,
        Alexander Viro <viro@...iv.linux.org.uk>,
        linux-fsdevel@...r.kernel.org
Subject: [PATCH RFC 08/13] fs/coredump: simplify the printing with '%pD' and '%pd' specifier

After the behavior of '%pD' is changed to print the full path of file,
the printing of dentry and struct file name can be simplified.

Given the space with proper length would be allocated in vprintk_store(),
it is worthy of dropping kmalloc()/kfree() to avoid additional space
allocation.

Cc: Alexander Viro <viro@...iv.linux.org.uk>
Cc: linux-fsdevel@...r.kernel.org
Cc: linux-kernel@...r.kernel.org
Signed-off-by: Jia He <justin.he@....com>
---
 fs/coredump.c | 26 ++++----------------------
 1 file changed, 4 insertions(+), 22 deletions(-)

diff --git a/fs/coredump.c b/fs/coredump.c
index 07afb5ddb1c4..88063056a801 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -156,35 +156,17 @@ int cn_esc_printf(struct core_name *cn, const char *fmt, ...)
 static int cn_print_exe_file(struct core_name *cn, bool name_only)
 {
 	struct file *exe_file;
-	char *pathbuf, *path, *ptr;
 	int ret;
 
 	exe_file = get_mm_exe_file(current->mm);
 	if (!exe_file)
 		return cn_esc_printf(cn, "%s (path unknown)", current->comm);
 
-	pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
-	if (!pathbuf) {
-		ret = -ENOMEM;
-		goto put_exe_file;
-	}
-
-	path = file_path(exe_file, pathbuf, PATH_MAX);
-	if (IS_ERR(path)) {
-		ret = PTR_ERR(path);
-		goto free_buf;
-	}
-
-	if (name_only) {
-		ptr = strrchr(path, '/');
-		if (ptr)
-			path = ptr + 1;
-	}
-	ret = cn_esc_printf(cn, "%s", path);
+	if (name_only)
+		ret = cn_esc_printf(cn, "%pd", exe_file->f_path.dentry);
+	else
+		ret = cn_esc_printf(cn, "%pD", exe_file);
 
-free_buf:
-	kfree(pathbuf);
-put_exe_file:
 	fput(exe_file);
 	return ret;
 }
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ