aboutsummaryrefslogtreecommitdiffstats
path: root/fs/dax.c
diff options
context:
space:
mode:
authorJeff Moyer <jmoyer@redhat.com>2017-11-14 20:37:27 -0500
committerDan Williams <dan.j.williams@intel.com>2017-11-14 23:16:55 -0500
commit957ac8c421ad8b5eef9b17fe98e146d8311a541e (patch)
treee12715f967f9d8c3e44929fd253eee4c45d1e821 /fs/dax.c
parent6a21586a637e624ae736f94aeb0839f6a1dd0411 (diff)
dax: fix PMD faults on zero-length files
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. Cc: <stable@vger.kernel.org> Fixes: 642261ac995e ("dax: add struct iomap based DAX PMD support") Signed-off-by: Jeff Moyer <jmoyer@redhat.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Diffstat (limited to 'fs/dax.c')
-rw-r--r--fs/dax.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/fs/dax.c b/fs/dax.c
index 27ba300660ff..f757cd0e2d07 100644
--- a/fs/dax.c
+++ b/fs/dax.c
@@ -1333,7 +1333,7 @@ static int dax_iomap_pmd_fault(struct vm_fault *vmf, pfn_t *pfnp,
1333 * this is a reliable test. 1333 * this is a reliable test.
1334 */ 1334 */
1335 pgoff = linear_page_index(vma, pmd_addr); 1335 pgoff = linear_page_index(vma, pmd_addr);
1336 max_pgoff = (i_size_read(inode) - 1) >> PAGE_SHIFT; 1336 max_pgoff = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE);
1337 1337
1338 trace_dax_pmd_fault(inode, vmf, max_pgoff, 0); 1338 trace_dax_pmd_fault(inode, vmf, max_pgoff, 0);
1339 1339
@@ -1357,13 +1357,13 @@ static int dax_iomap_pmd_fault(struct vm_fault *vmf, pfn_t *pfnp,
1357 if ((pmd_addr + PMD_SIZE) > vma->vm_end) 1357 if ((pmd_addr + PMD_SIZE) > vma->vm_end)
1358 goto fallback; 1358 goto fallback;
1359 1359
1360 if (pgoff > max_pgoff) { 1360 if (pgoff >= max_pgoff) {
1361 result = VM_FAULT_SIGBUS; 1361 result = VM_FAULT_SIGBUS;
1362 goto out; 1362 goto out;
1363 } 1363 }
1364 1364
1365 /* If the PMD would extend beyond the file size */ 1365 /* If the PMD would extend beyond the file size */
1366 if ((pgoff | PG_PMD_COLOUR) > max_pgoff) 1366 if ((pgoff | PG_PMD_COLOUR) >= max_pgoff)
1367 goto fallback; 1367 goto fallback;
1368 1368
1369 /* 1369 /*