[Devel,RHEL7,COMMIT] vfs: guard end of device for mpage interface

Submitted by Konstantin Khorenko on Oct. 24, 2016, 11:55 a.m.


Message ID 201610241155.u9OBtdvS022781@finist_cl7.x64_64.work.ct
State New
Series "vfs: avoid attempts to access beyond end of device"
Headers show

Commit Message

Konstantin Khorenko Oct. 24, 2016, 11:55 a.m.
The commit is pushed to "branch-rh7-3.10.0-327.36.1.vz7.19.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-327.36.1.vz7.19.3
commit ee6150583a86e2e0bc9ad82696e98d1a24fec16b
Author: Maxim Patlasov <mpatlasov@virtuozzo.com>
Date:   Mon Oct 24 15:55:39 2016 +0400

    vfs: guard end of device for mpage interface
    The patch backports 4db96b71e3caea5bb39053d57683129e0682c66f from mainline:
        vfs: guard end of device for mpage interface
        Add guard_bio_eod() check for mpage code in order to allow us to do IO
        even on the odd last sectors of a device, even if the block size is some
        multiple of the physical sector size.
        Using mpage_readpages() for block device requires this guard check.
        Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
        Cc: Jens Axboe <axboe@kernel.dk>
        Cc: Alexander Viro <viro@zeniv.linux.org.uk>
        Cc: Jeff Moyer <jmoyer@redhat.com>
        Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
        Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
    Signed-off-by: Maxim Patlasov <mpatlasov@virtuozzo.com>
 fs/buffer.c   | 2 +-
 fs/internal.h | 5 +++++
 fs/mpage.c    | 2 ++
 3 files changed, 8 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/fs/buffer.c b/fs/buffer.c
index a7cb15c..c45200d 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -2982,7 +2982,7 @@  static void end_bio_bh_io_sync(struct bio *bio, int err)
  * errors, this only handles the "we need to be able to
  * do IO at the final sector" case.
-static void guard_bio_eod(int rw, struct bio *bio)
+void guard_bio_eod(int rw, struct bio *bio)
 	sector_t maxsector;
 	struct bio_vec *bvec = &bio->bi_io_vec[bio->bi_vcnt - 1];
diff --git a/fs/internal.h b/fs/internal.h
index b538b3d..6f4120e 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -38,6 +38,11 @@  static inline int __sync_blockdev(struct block_device *bdev, int wait)
+ * buffer.c
+ */
+extern void guard_bio_eod(int rw, struct bio *bio);
  * char_dev.c
 extern void __init chrdev_init(void);
diff --git a/fs/mpage.c b/fs/mpage.c
index 0face1c..c4f7bf6c 100644
--- a/fs/mpage.c
+++ b/fs/mpage.c
@@ -28,6 +28,7 @@ 
 #include <linux/backing-dev.h>
 #include <linux/pagevec.h>
 #include <linux/cleancache.h>
+#include "internal.h"
  * I/O completion handler for multipage BIOs.
@@ -74,6 +75,7 @@  static void mpage_end_io(struct bio *bio, int err)
 static struct bio *mpage_bio_submit(int rw, struct bio *bio)
 	bio->bi_end_io = mpage_end_io;
+	guard_bio_eod(rw, bio);
 	submit_bio(rw, bio);
 	return NULL;