Skip to content

Commit 3d035f5

Browse files
prarittorvalds
authored andcommitted
drivers/char/hpet.c: allow user controlled mmap for user processes
The CONFIG_HPET_MMAP Kconfig option exposes the memory map of the HPET registers to userspace. The Kconfig help points out that in some cases this can be a security risk as some systems may erroneously configure the map such that additional data is exposed to userspace. This is a problem for distributions -- some users want the MMAP functionality but it comes with a significant security risk. In an effort to mitigate this risk, and due to the low number of users of the MMAP functionality, I've introduced a kernel parameter, hpet_mmap_enable, that is required in order to actually have the HPET MMAP exposed. Signed-off-by: Prarit Bhargava <prarit@redhat.com> Acked-by: Matt Wilson <msw@amazon.com> Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Cc: Randy Dunlap <rdunlap@infradead.org> Cc: Tomas Winkler <tomas.winkler@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 72403b4 commit 3d035f5

3 files changed

Lines changed: 33 additions & 4 deletions

File tree

‎Documentation/kernel-parameters.txt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
10701070
VIA, nVidia)
10711071
verbose: show contents of HPET registers during setup
10721072

1073+
hpet_mmap= [X86, HPET_MMAP] Allow userspace to mmap HPET
1074+
registers. Default set by CONFIG_HPET_MMAP_DEFAULT.
1075+
10731076
hugepages= [HW,X86-32,IA-64] HugeTLB pages to allocate at boot.
10741077
hugepagesz= [HW,IA-64,PPC,X86-64] The size of the HugeTLB pages.
10751078
On x86-64 and powerpc, this option can be specified

‎drivers/char/Kconfig‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,10 +522,16 @@ config HPET_MMAP
522522
If you say Y here, user applications will be able to mmap
523523
the HPET registers.
524524

525+
config HPET_MMAP_DEFAULT
526+
bool "Enable HPET MMAP access by default"
527+
default y
528+
depends on HPET_MMAP
529+
help
525530
In some hardware implementations, the page containing HPET
526531
registers may also contain other things that shouldn't be
527-
exposed to the user. If this applies to your hardware,
528-
say N here.
532+
exposed to the user. This option selects the default (if
533+
kernel parameter hpet_mmap is not set) user access to the
534+
registers for applications that require it.
529535

530536
config HANGCHECK_TIMER
531537
tristate "Hangcheck timer"

‎drivers/char/hpet.c‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,29 @@ static unsigned int hpet_poll(struct file *file, poll_table * wait)
367367
return 0;
368368
}
369369

370+
#ifdef CONFIG_HPET_MMAP
371+
#ifdef CONFIG_HPET_MMAP_DEFAULT
372+
static int hpet_mmap_enabled = 1;
373+
#else
374+
static int hpet_mmap_enabled = 0;
375+
#endif
376+
377+
static __init int hpet_mmap_enable(char *str)
378+
{
379+
get_option(&str, &hpet_mmap_enabled);
380+
pr_info("HPET mmap %s\n", hpet_mmap_enabled ? "enabled" : "disabled");
381+
return 1;
382+
}
383+
__setup("hpet_mmap", hpet_mmap_enable);
384+
370385
static int hpet_mmap(struct file *file, struct vm_area_struct *vma)
371386
{
372-
#ifdef CONFIG_HPET_MMAP
373387
struct hpet_dev *devp;
374388
unsigned long addr;
375389

390+
if (!hpet_mmap_enabled)
391+
return -EACCES;
392+
376393
devp = file->private_data;
377394
addr = devp->hd_hpets->hp_hpet_phys;
378395

@@ -381,10 +398,13 @@ static int hpet_mmap(struct file *file, struct vm_area_struct *vma)
381398

382399
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
383400
return vm_iomap_memory(vma, addr, PAGE_SIZE);
401+
}
384402
#else
403+
static int hpet_mmap(struct file *file, struct vm_area_struct *vma)
404+
{
385405
return -ENOSYS;
386-
#endif
387406
}
407+
#endif
388408

389409
static int hpet_fasync(int fd, struct file *file, int on)
390410
{

0 commit comments

Comments
 (0)