From 3936ce92d2c6f455562e97a1c340ba6b7ac4257d Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Sun, 3 Apr 2022 14:44:42 +0200 Subject: [PATCH] 4.19-stable patches added patches: gfs2-make-sure-fitrim-minlen-is-rounded-up-to-fs-block-size.patch --- ...inlen-is-rounded-up-to-fs-block-size.patch | 42 +++++++++++++++++++ queue-4.19/series | 1 + 2 files changed, 43 insertions(+) create mode 100644 queue-4.19/gfs2-make-sure-fitrim-minlen-is-rounded-up-to-fs-block-size.patch diff --git a/queue-4.19/gfs2-make-sure-fitrim-minlen-is-rounded-up-to-fs-block-size.patch b/queue-4.19/gfs2-make-sure-fitrim-minlen-is-rounded-up-to-fs-block-size.patch new file mode 100644 index 00000000000..9110f8baed9 --- /dev/null +++ b/queue-4.19/gfs2-make-sure-fitrim-minlen-is-rounded-up-to-fs-block-size.patch @@ -0,0 +1,42 @@ +From 27ca8273fda398638ca994a207323a85b6d81190 Mon Sep 17 00:00:00 2001 +From: Andrew Price +Date: Tue, 22 Mar 2022 19:05:51 +0000 +Subject: gfs2: Make sure FITRIM minlen is rounded up to fs block size + +From: Andrew Price + +commit 27ca8273fda398638ca994a207323a85b6d81190 upstream. + +Per fstrim(8) we must round up the minlen argument to the fs block size. +The current calculation doesn't take into account devices that have a +discard granularity and requested minlen less than 1 fs block, so the +value can get shifted away to zero in the translation to fs blocks. + +The zero minlen passed to gfs2_rgrp_send_discards() then allows +sb_issue_discard() to be called with nr_sects == 0 which returns -EINVAL +and results in gfs2_rgrp_send_discards() returning -EIO. + +Make sure minlen is never < 1 fs block by taking the max of the +requested minlen and the fs block size before comparing to the device's +discard granularity and shifting to fs blocks. + +Fixes: 076f0faa764ab ("GFS2: Fix FITRIM argument handling") +Signed-off-by: Andrew Price +Signed-off-by: Andreas Gruenbacher +Signed-off-by: Greg Kroah-Hartman +--- + fs/gfs2/rgrp.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +--- a/fs/gfs2/rgrp.c ++++ b/fs/gfs2/rgrp.c +@@ -1406,7 +1406,8 @@ int gfs2_fitrim(struct file *filp, void + + start = r.start >> bs_shift; + end = start + (r.len >> bs_shift); +- minlen = max_t(u64, r.minlen, ++ minlen = max_t(u64, r.minlen, sdp->sd_sb.sb_bsize); ++ minlen = max_t(u64, minlen, + q->limits.discard_granularity) >> bs_shift; + + if (end <= start || minlen > sdp->sd_max_rg_data) diff --git a/queue-4.19/series b/queue-4.19/series index 2a2e563c67a..99206f79d9f 100644 --- a/queue-4.19/series +++ b/queue-4.19/series @@ -240,3 +240,4 @@ ubifs-fix-read-out-of-bounds-in-ubifs_wbuf_write_nolock.patch ubifs-rename_whiteout-correct-old_dir-size-computing.patch can-mcba_usb-mcba_usb_start_xmit-fix-double-dev_kfree_skb-in-error-path.patch can-mcba_usb-properly-check-endpoint-type.patch +gfs2-make-sure-fitrim-minlen-is-rounded-up-to-fs-block-size.patch -- 2.47.3