Patch "dax: fix PMD faults on zero-length files" has been added to the 4.14-stable tree
Subsystems (3)
This is a note to let you know that I've just added the patch titled
dax: fix PMD faults on zero-length files
to the 4.14-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
dax-fix-pmd-faults-on-zero-length-files.patch
and it can be found in the queue-4.14 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From
957ac8c421ad8b5eef9b17fe98e146d8311a541eMon Sep 17 00:00:00 2001
From: Jeff Moyer <[email protected]>
Date: Tue, 14 Nov 2017 20:37:27 -0500
Subject: dax: fix PMD faults on zero-length files
From: Jeff Moyer <[email protected]>
commit 957ac8c421ad8b5eef9b17fe98e146d8311a541e upstream.
PMD faults on a zero length file on a file system mounted with -o dax will not generate SIGBUS as expected.
fd = open(...O_TRUNC);
addr = mmap(NULL, 2*1024*1024, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
*addr = 'a';
<expect SIGBUS>The problem is this code in dax_iomap_pmd_fault:
max_pgoff = (i_size_read(inode) - 1) >> PAGE_SHIFT;
If the inode size is zero, we end up with a max_pgoff that is way larger than 0. :) Fix it by using DIV_ROUND_UP, as is done elsewhere in the kernel.
I tested this with some simple test code that ensured that SIGBUS was received where expected.
--- fs/dax.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/dax.c +3 -3
@@ -1327,7 +1327,7 @@ static int dax_iomap_pmd_fault(struct vm* this is a reliable test. */ pgoff =linear_page_index (vma, pmd_addr); - max_pgoff = (i_size_read (inode) -1 ) >>PAGE_SHIFT ; + max_pgoff =DIV_ROUND_UP (i_size_read (inode),PAGE_SIZE );trace_dax_pmd_fault (inode, vmf, max_pgoff,0 );
@@ -1351,13 +1351,13 @@ static int dax_iomap_pmd_fault(struct vmif ((pmd_addr +PMD_SIZE ) > vma->vm_end) goto fallback; -if (pgoff > max_pgoff) { +if (pgoff >= max_pgoff) { result =VM_FAULT_SIGBUS ; goto out; }/* If the PMD would extend beyond the file size */ -if ((pgoff |PG_PMD_COLOUR ) > max_pgoff) +if ((pgoff |PG_PMD_COLOUR ) >= max_pgoff) goto fallback;/*
Patches currently in stable-queue which might be from [email protected] are
queue-4.14/dax-fix-pmd-faults-on-zero-length-files.patch