aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLinus Torvalds2019-09-21 09:34:29 -0700
committerLinus Torvalds2019-09-21 09:34:29 -0700
commit56c1e8343494f0a315c99964ea1a952478394a8d (patch)
tree174cc3f4782d00fe0f8e47bff1ae8102d26cdccc /lib
parentf97c81dc6ca5996560b3944064f63fc87eb18d00 (diff)
parentae88de56a1893bdccc7b5af8c12556de649d675e (diff)
Merge tag 'printk-for-5.4' of git://git.kernel.org/pub/scm/linux/kernel/git/pmladek/printk
Pull printk updates from Petr Mladek: - Fix off-by-one error when calculating messages that might fit into kmsg buffer. It causes occasional omitting of the last message. - Add missing pointer check in %pD format modifier handling. - Some clean up * tag 'printk-for-5.4' of git://git.kernel.org/pub/scm/linux/kernel/git/pmladek/printk: ABI: Update dev-kmsg documentation to match current kernel behaviour printk: Replace strncmp() with str_has_prefix() lib/test_printf: Remove obvious comments from %pd and %pD tests lib/test_printf: Add test of null/invalid pointer dereference for dentry vsprintf: Prevent crash when dereferencing invalid pointers for %pD printk: Do not lose last line in kmsg buffer dump
Diffstat (limited to 'lib')
-rw-r--r--lib/test_printf.c5
-rw-r--r--lib/vsprintf.c13
2 files changed, 15 insertions, 3 deletions
diff --git a/lib/test_printf.c b/lib/test_printf.c
index 944eb50f3862..5d94cbff2120 100644
--- a/lib/test_printf.c
+++ b/lib/test_printf.c
@@ -455,6 +455,11 @@ dentry(void)
test("foo", "%pd", &test_dentry[0]);
test("foo", "%pd2", &test_dentry[0]);
+ test("(null)", "%pd", NULL);
+ test("(efault)", "%pd", PTR_INVALID);
+ test("(null)", "%pD", NULL);
+ test("(efault)", "%pD", PTR_INVALID);
+
test("romeo", "%pd", &test_dentry[3]);
test("alfa/romeo", "%pd2", &test_dentry[3]);
test("bravo/alfa/romeo", "%pd3", &test_dentry[3]);
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index b0967cf17137..e78017a3e1bd 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -869,6 +869,15 @@ char *dentry_name(char *buf, char *end, const struct dentry *d, struct printf_sp
return widen_string(buf, n, end, spec);
}
+static noinline_for_stack
+char *file_dentry_name(char *buf, char *end, const struct file *f,
+ struct printf_spec spec, const char *fmt)
+{
+ if (check_pointer(&buf, end, f, spec))
+ return buf;
+
+ return dentry_name(buf, end, f->f_path.dentry, spec, fmt);
+}
#ifdef CONFIG_BLOCK
static noinline_for_stack
char *bdev_name(char *buf, char *end, struct block_device *bdev,
@@ -2166,9 +2175,7 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
case 'C':
return clock(buf, end, ptr, spec, fmt);
case 'D':
- return dentry_name(buf, end,
- ((const struct file *)ptr)->f_path.dentry,
- spec, fmt);
+ return file_dentry_name(buf, end, ptr, spec, fmt);
#ifdef CONFIG_BLOCK
case 'g':
return bdev_name(buf, end, ptr, spec, fmt);