Re: [PATCH] KERNEL: resource: Fix bug on leakage in /proc/iomem file

From: Kees Cook
Date: Wed Apr 06 2016 - 14:21:34 EST


On Wed, Apr 6, 2016 at 11:05 AM, <ed@xxxxxxxxxx> wrote:
> First, I wrote your attached patch, but then I thought zeroing other
> /proc/iomem values would be better. So I changed it.
>
> Most distros don't use KASLR, but they use kptr_restrict. Without KASLR,

Well, hopefully that'll change over time. :)

> kptr_restirct most likely useless. As you said these things should be done
> long ago

This results in a warning, but the kernel's printf formatting supports it:

kernel/resource.c: In function âr_showâ:
kernel/resource.c:118:4: warning: '0' flag used with â%pâ gnu_printf
format [-Wformat=]

I'm not sure how to best suppress that...

diff --git a/kernel/resource.c b/kernel/resource.c
index 2e78ead30934..d5881d143fb6 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -111,10 +111,10 @@ static int r_show(struct seq_file *m, void *v)
for (depth = 0, p = r; depth < MAX_IORES_LEVEL; depth++, p = p->parent)
if (p->parent == root)
break;
- seq_printf(m, "%*s%0*llx-%0*llx : %s\n",
+ seq_printf(m, "%*s%0*pK-%0*pK : %s\n",
depth * 2, "",
- width, (unsigned long long) r->start,
- width, (unsigned long long) r->end,
+ width, (void *) r->start,
+ width, (void *) r->end,
r->name ? r->name : "<BAD>");
return 0;
}

-Kees

--
Kees Cook
Chrome OS & Brillo Security