aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2016-02-11 19:13:00 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2016-02-11 21:35:48 -0500
commit7eb391299419a03cbe0fa5ab0e6b0932e42c7a36 (patch)
treee531c88307514653e1fa5de03ec37fdf81bf3a6c /lib
parent62eb320ab077890dbbcc28343fa6432a82a10c35 (diff)
vsprintf: kptr_restrict is okay in IRQ when 2
The kptr_restrict flag, when set to 1, only prints the kernel address when the user has CAP_SYSLOG. When it is set to 2, the kernel address is always printed as zero. When set to 1, this needs to check whether or not we're in IRQ. However, when set to 2, this check is unneccessary, and produces confusing results in dmesg. Thus, only make sure we're not in IRQ when mode 1 is used, but not mode 2. [akpm@linux-foundation.org: coding-style fixes] Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk> Cc: Kees Cook <keescook@chromium.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/vsprintf.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 48ff9c36644d..f44e178e6ede 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1590,22 +1590,23 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
1590 return buf; 1590 return buf;
1591 } 1591 }
1592 case 'K': 1592 case 'K':
1593 /*
1594 * %pK cannot be used in IRQ context because its test
1595 * for CAP_SYSLOG would be meaningless.
1596 */
1597 if (kptr_restrict && (in_irq() || in_serving_softirq() ||
1598 in_nmi())) {
1599 if (spec.field_width == -1)
1600 spec.field_width = default_width;
1601 return string(buf, end, "pK-error", spec);
1602 }
1603
1604 switch (kptr_restrict) { 1593 switch (kptr_restrict) {
1605 case 0: 1594 case 0:
1606 /* Always print %pK values */ 1595 /* Always print %pK values */
1607 break; 1596 break;
1608 case 1: { 1597 case 1: {
1598 const struct cred *cred;
1599
1600 /*
1601 * kptr_restrict==1 cannot be used in IRQ context
1602 * because its test for CAP_SYSLOG would be meaningless.
1603 */
1604 if (in_irq() || in_serving_softirq() || in_nmi()) {
1605 if (spec.field_width == -1)
1606 spec.field_width = default_width;
1607 return string(buf, end, "pK-error", spec);
1608 }
1609
1609 /* 1610 /*
1610 * Only print the real pointer value if the current 1611 * Only print the real pointer value if the current
1611 * process has CAP_SYSLOG and is running with the 1612 * process has CAP_SYSLOG and is running with the
@@ -1615,8 +1616,7 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
1615 * leak pointer values if a binary opens a file using 1616 * leak pointer values if a binary opens a file using
1616 * %pK and then elevates privileges before reading it. 1617 * %pK and then elevates privileges before reading it.
1617 */ 1618 */
1618 const struct cred *cred = current_cred(); 1619 cred = current_cred();
1619
1620 if (!has_capability_noaudit(current, CAP_SYSLOG) || 1620 if (!has_capability_noaudit(current, CAP_SYSLOG) ||
1621 !uid_eq(cred->euid, cred->uid) || 1621 !uid_eq(cred->euid, cred->uid) ||
1622 !gid_eq(cred->egid, cred->gid)) 1622 !gid_eq(cred->egid, cred->gid))