* [PATCH] vsprintf: kptr_restrict is okay in IRQ when 2
@ 2016-02-05 13:45 Jason A. Donenfeld
2016-02-05 20:46 ` Kees Cook
0 siblings, 1 reply; 7+ messages in thread
From: Jason A. Donenfeld @ 2016-02-05 13:45 UTC (permalink / raw)
To: akpm, keescook, linux-kernel; +Cc: Jason A. Donenfeld
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.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
lib/vsprintf.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 80d8ce5..fab875f 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1609,8 +1609,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
* %pK cannot be used in IRQ context because its test
* for CAP_SYSLOG would be meaningless.
*/
- if (kptr_restrict && (in_irq() || in_serving_softirq() ||
- in_nmi())) {
+ if (kptr_restrict == 1 && (in_irq() || in_serving_softirq() ||
+ in_nmi())) {
if (spec.field_width == -1)
spec.field_width = default_width;
return string(buf, end, "pK-error", spec);
--
2.7.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] vsprintf: kptr_restrict is okay in IRQ when 2
2016-02-05 13:45 [PATCH] vsprintf: kptr_restrict is okay in IRQ when 2 Jason A. Donenfeld
@ 2016-02-05 20:46 ` Kees Cook
2016-02-05 21:56 ` Jason A. Donenfeld
2016-02-05 22:03 ` [PATCH v2] " Jason A. Donenfeld
0 siblings, 2 replies; 7+ messages in thread
From: Kees Cook @ 2016-02-05 20:46 UTC (permalink / raw)
To: Jason A. Donenfeld; +Cc: Andrew Morton, LKML
On Fri, Feb 5, 2016 at 5:45 AM, Jason A. Donenfeld <Jason@zx2c4.com> wrote:
> 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.
Cool, nice fix.
>
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> ---
> lib/vsprintf.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index 80d8ce5..fab875f 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -1609,8 +1609,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
> * %pK cannot be used in IRQ context because its test
> * for CAP_SYSLOG would be meaningless.
> */
> - if (kptr_restrict && (in_irq() || in_serving_softirq() ||
> - in_nmi())) {
> + if (kptr_restrict == 1 && (in_irq() || in_serving_softirq() ||
> + in_nmi())) {
Instead of doing a double-check of kptr_restrict, how about moving
this logic down into the "case 1" test? I think that would be more
readable in the end.
-Kees
> if (spec.field_width == -1)
> spec.field_width = default_width;
> return string(buf, end, "pK-error", spec);
> --
> 2.7.0
>
--
Kees Cook
Chrome OS & Brillo Security
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] vsprintf: kptr_restrict is okay in IRQ when 2
2016-02-05 20:46 ` Kees Cook
@ 2016-02-05 21:56 ` Jason A. Donenfeld
2016-02-05 22:03 ` [PATCH v2] " Jason A. Donenfeld
1 sibling, 0 replies; 7+ messages in thread
From: Jason A. Donenfeld @ 2016-02-05 21:56 UTC (permalink / raw)
To: Kees Cook; +Cc: Andrew Morton, LKML
On Fri, Feb 5, 2016 at 9:46 PM, Kees Cook <keescook@chromium.org> wrote:
>
> Instead of doing a double-check of kptr_restrict, how about moving
> this logic down into the "case 1" test? I think that would be more
> readable in the end.
Good thinking. Will roll v2.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2] vsprintf: kptr_restrict is okay in IRQ when 2
2016-02-05 20:46 ` Kees Cook
2016-02-05 21:56 ` Jason A. Donenfeld
@ 2016-02-05 22:03 ` Jason A. Donenfeld
2016-02-05 22:14 ` Kees Cook
1 sibling, 1 reply; 7+ messages in thread
From: Jason A. Donenfeld @ 2016-02-05 22:03 UTC (permalink / raw)
To: keescook, akpm, linux-kernel; +Cc: Jason A. Donenfeld
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.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
lib/vsprintf.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 80d8ce5..ee1e24e 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1605,22 +1605,23 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
return buf;
}
case 'K':
- /*
- * %pK cannot be used in IRQ context because its test
- * for CAP_SYSLOG would be meaningless.
- */
- if (kptr_restrict && (in_irq() || in_serving_softirq() ||
- in_nmi())) {
- if (spec.field_width == -1)
- spec.field_width = default_width;
- return string(buf, end, "pK-error", spec);
- }
-
switch (kptr_restrict) {
case 0:
/* Always print %pK values */
break;
case 1: {
+ const struct cred *cred;
+
+ /*
+ * kptr_restrict==2 cannot be used in IRQ context because
+ * its test for CAP_SYSLOG would be meaningless.
+ */
+ if (in_irq() || in_serving_softirq() || in_nmi()) {
+ if (spec.field_width == -1)
+ spec.field_width = default_width;
+ return string(buf, end, "pK-error", spec);
+ }
+
/*
* Only print the real pointer value if the current
* process has CAP_SYSLOG and is running with the
@@ -1630,8 +1631,7 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
* leak pointer values if a binary opens a file using
* %pK and then elevates privileges before reading it.
*/
- const struct cred *cred = current_cred();
-
+ cred = current_cred();
if (!has_capability_noaudit(current, CAP_SYSLOG) ||
!uid_eq(cred->euid, cred->uid) ||
!gid_eq(cred->egid, cred->gid))
--
2.7.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] vsprintf: kptr_restrict is okay in IRQ when 2
2016-02-05 22:03 ` [PATCH v2] " Jason A. Donenfeld
@ 2016-02-05 22:14 ` Kees Cook
2016-02-07 21:53 ` Rasmus Villemoes
0 siblings, 1 reply; 7+ messages in thread
From: Kees Cook @ 2016-02-05 22:14 UTC (permalink / raw)
To: Jason A. Donenfeld; +Cc: Andrew Morton, LKML
On Fri, Feb 5, 2016 at 2:03 PM, Jason A. Donenfeld <Jason@zx2c4.com> wrote:
> 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.
>
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Thanks!
Acked-by: Kees Cook <keescook@chromium.org>
-Kees
> ---
> lib/vsprintf.c | 26 +++++++++++++-------------
> 1 file changed, 13 insertions(+), 13 deletions(-)
>
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index 80d8ce5..ee1e24e 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -1605,22 +1605,23 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
> return buf;
> }
> case 'K':
> - /*
> - * %pK cannot be used in IRQ context because its test
> - * for CAP_SYSLOG would be meaningless.
> - */
> - if (kptr_restrict && (in_irq() || in_serving_softirq() ||
> - in_nmi())) {
> - if (spec.field_width == -1)
> - spec.field_width = default_width;
> - return string(buf, end, "pK-error", spec);
> - }
> -
> switch (kptr_restrict) {
> case 0:
> /* Always print %pK values */
> break;
> case 1: {
> + const struct cred *cred;
> +
> + /*
> + * kptr_restrict==2 cannot be used in IRQ context because
> + * its test for CAP_SYSLOG would be meaningless.
> + */
> + if (in_irq() || in_serving_softirq() || in_nmi()) {
> + if (spec.field_width == -1)
> + spec.field_width = default_width;
> + return string(buf, end, "pK-error", spec);
> + }
> +
> /*
> * Only print the real pointer value if the current
> * process has CAP_SYSLOG and is running with the
> @@ -1630,8 +1631,7 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
> * leak pointer values if a binary opens a file using
> * %pK and then elevates privileges before reading it.
> */
> - const struct cred *cred = current_cred();
> -
> + cred = current_cred();
> if (!has_capability_noaudit(current, CAP_SYSLOG) ||
> !uid_eq(cred->euid, cred->uid) ||
> !gid_eq(cred->egid, cred->gid))
> --
> 2.7.0
>
--
Kees Cook
Chrome OS & Brillo Security
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] vsprintf: kptr_restrict is okay in IRQ when 2
2016-02-05 22:14 ` Kees Cook
@ 2016-02-07 21:53 ` Rasmus Villemoes
2016-02-08 4:30 ` [PATCH v3] " Jason A. Donenfeld
0 siblings, 1 reply; 7+ messages in thread
From: Rasmus Villemoes @ 2016-02-07 21:53 UTC (permalink / raw)
To: Kees Cook; +Cc: Jason A. Donenfeld, Andrew Morton, LKML
On Fri, Feb 05 2016, Kees Cook <keescook@chromium.org> wrote:
>> switch (kptr_restrict) {
>> case 0:
>> /* Always print %pK values */
>> break;
>> case 1: {
>> + const struct cred *cred;
>> +
>> + /*
>> + * kptr_restrict==2 cannot be used in IRQ context because
^
should be 1, right?
Rasmus
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3] vsprintf: kptr_restrict is okay in IRQ when 2
2016-02-07 21:53 ` Rasmus Villemoes
@ 2016-02-08 4:30 ` Jason A. Donenfeld
0 siblings, 0 replies; 7+ messages in thread
From: Jason A. Donenfeld @ 2016-02-08 4:30 UTC (permalink / raw)
To: Rasmus Villemoes, Andrew Morton, Kees Cook, LKML; +Cc: Jason A. Donenfeld
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.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
lib/vsprintf.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 80d8ce5..37c7068 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1605,22 +1605,23 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
return buf;
}
case 'K':
- /*
- * %pK cannot be used in IRQ context because its test
- * for CAP_SYSLOG would be meaningless.
- */
- if (kptr_restrict && (in_irq() || in_serving_softirq() ||
- in_nmi())) {
- if (spec.field_width == -1)
- spec.field_width = default_width;
- return string(buf, end, "pK-error", spec);
- }
-
switch (kptr_restrict) {
case 0:
/* Always print %pK values */
break;
case 1: {
+ const struct cred *cred;
+
+ /*
+ * kptr_restrict==1 cannot be used in IRQ context because
+ * its test for CAP_SYSLOG would be meaningless.
+ */
+ if (in_irq() || in_serving_softirq() || in_nmi()) {
+ if (spec.field_width == -1)
+ spec.field_width = default_width;
+ return string(buf, end, "pK-error", spec);
+ }
+
/*
* Only print the real pointer value if the current
* process has CAP_SYSLOG and is running with the
@@ -1630,8 +1631,7 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
* leak pointer values if a binary opens a file using
* %pK and then elevates privileges before reading it.
*/
- const struct cred *cred = current_cred();
-
+ cred = current_cred();
if (!has_capability_noaudit(current, CAP_SYSLOG) ||
!uid_eq(cred->euid, cred->uid) ||
!gid_eq(cred->egid, cred->gid))
--
2.7.0
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-02-08 4:30 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-05 13:45 [PATCH] vsprintf: kptr_restrict is okay in IRQ when 2 Jason A. Donenfeld
2016-02-05 20:46 ` Kees Cook
2016-02-05 21:56 ` Jason A. Donenfeld
2016-02-05 22:03 ` [PATCH v2] " Jason A. Donenfeld
2016-02-05 22:14 ` Kees Cook
2016-02-07 21:53 ` Rasmus Villemoes
2016-02-08 4:30 ` [PATCH v3] " Jason A. Donenfeld
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®