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-next>] [day] [month] [year] [list]
Message-ID: <09f11651f0e913e159b955ac447cd8cadf36cb0d.camel@perches.com>
Date:   Fri, 14 Aug 2020 10:53:03 -0700
From:   Joe Perches <joe@...ches.com>
To:     LKML <linux-kernel@...r.kernel.org>
Cc:     Petr Mladek <pmladek@...e.com>,
        Steven Rostedt <rostedt@...dmis.org>,
        Sergey Senozhatsky <sergey.senozhatsky@...il.com>,
        Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        Rasmus Villemoes <linux@...musvillemoes.dk>
Subject: [RFC PATCH] vsprintf: Add %pv extension replacement for
 print_vma_addr

There is a print_vma_addr function used several places
that requires KERN_CONT use.

Add a %pv mechanism to avoid the need for KERN_CONT.

An example conversion is arch/x86/kernel/signal.c

from:
	if (show_unhandled_signals && printk_ratelimit()) {
		printk("%s"
		       "%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx",
		       task_pid_nr(current) > 1 ? KERN_INFO : KERN_EMERG,
		       me->comm, me->pid, where, frame,
		       regs->ip, regs->sp, regs->orig_ax);
		print_vma_addr(KERN_CONT " in ", regs->ip);
		pr_cont("\n");
to:
		printk("%s"
		       "%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx in %pv\n",
		       task_pid_nr(current) > 1 ? KERN_INFO : KERN_EMERG,
		       me->comm, me->pid, where, frame,
		       regs->ip, regs->sp, regs->orig_ax, (void *)regs->ip);
---
 lib/vsprintf.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index c155769559ab..654402c43f8d 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -995,6 +995,12 @@ static const struct printf_spec default_dec_spec = {
 	.precision = -1,
 };
 
+static const struct printf_spec default_hex_spec = {
+	.base = 16,
+	.precision = -1,
+	.flags = SMALL,
+};
+
 static const struct printf_spec default_dec02_spec = {
 	.base = 10,
 	.field_width = 2,
@@ -2089,6 +2095,50 @@ char *fwnode_string(char *buf, char *end, struct fwnode_handle *fwnode,
 	return widen_string(buf, buf - buf_start, end, spec);
 }
 
+static noinline_for_stack
+char *vma_addr(char *buf, char *end, void *ip,
+	       struct printf_spec spec, const char *fmt)
+{
+#ifdef CONFIG_MMU
+	struct mm_struct *mm = current->mm;
+	struct vm_area_struct *vma;
+
+	/*
+	 * we might be running from an atomic context so we cannot sleep
+	 */
+	if (!mmap_read_trylock(mm))
+		return buf;
+
+	vma = find_vma(mm, (unsigned long)ip);
+	if (vma && vma->vm_file) {
+		char *p;
+		struct file *f = vma->vm_file;
+		char *page = (char *)__get_free_page(GFP_NOWAIT);
+
+		if (page) {
+			p = file_path(f, page, PAGE_SIZE);
+			if (IS_ERR(p))
+				p = "?";
+			buf = string(buf, end, kbasename(p), default_str_spec);
+			buf = string_nocheck(buf, end, "[", default_str_spec);
+			buf = pointer_string(buf, end,
+					     (void *)vma->vm_start,
+					     default_hex_spec);
+			buf = string_nocheck(buf, end, "+", default_str_spec);
+			buf = pointer_string(buf, end,
+					     (void *)(vma->vm_end - vma->vm_start),
+					     default_hex_spec);
+			buf = string_nocheck(buf, end, "]", default_str_spec);
+			free_page((unsigned long)page);
+		}
+	}
+	mmap_read_unlock(mm);
+#else
+	buf = string_nocheck(buf, end, "CONFIG_MMU=n", default_str_spec);
+#endif
+	return buf;
+}
+
 /*
  * Show a '%p' thing.  A kernel extension is that the '%p' is followed
  * by an extra set of alphanumeric characters that are extended format
@@ -2254,6 +2304,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
 		return uuid_string(buf, end, ptr, spec, fmt);
 	case 'V':
 		return va_format(buf, end, ptr, spec, fmt);
+	case 'v':
+		return vma_addr(buf, end, ptr, spec, fmt);
 	case 'K':
 		return restricted_pointer(buf, end, ptr, spec);
 	case 'N':


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ