From e282a4043b52cdcd7c329ff20e490d7912b17ba8 Mon Sep 17 00:00:00 2001 From: Coly Li Date: Apr 13 2024 06:51:07 +0000 Subject: dm stats: check for and propagate alloc_percpu failure (git-fixes). --- diff --git a/patches.suse/dm-stats-check-for-and-propagate-alloc_percpu-failur-d3aa.patch b/patches.suse/dm-stats-check-for-and-propagate-alloc_percpu-failur-d3aa.patch new file mode 100644 index 0000000..453aaf3 --- /dev/null +++ b/patches.suse/dm-stats-check-for-and-propagate-alloc_percpu-failur-d3aa.patch @@ -0,0 +1,88 @@ +From d3aa3e060c4a80827eb801fc448debc9daa7c46b Mon Sep 17 00:00:00 2001 +From: Jiasheng Jiang +Date: Thu, 16 Mar 2023 14:55:06 +0800 +Subject: [PATCH] dm stats: check for and propagate alloc_percpu failure +Git-commit: d3aa3e060c4a80827eb801fc448debc9daa7c46b +Patch-mainline: v6.3-rc4 +References: git-fixes + +Check alloc_precpu()'s return value and return an error from +dm_stats_init() if it fails. Update alloc_dev() to fail if +dm_stats_init() does. + +Otherwise, a NULL pointer dereference will occur in dm_stats_cleanup() +even if dm-stats isn't being actively used. + +Fixes: fd2ed4d25270 ("dm: add statistics support") +Cc: stable@vger.kernel.org +Signed-off-by: Jiasheng Jiang +Signed-off-by: Mike Snitzer +Signed-off-by: Coly Li + +--- + drivers/md/dm-stats.c | 7 ++++++- + drivers/md/dm-stats.h | 2 +- + drivers/md/dm.c | 4 +++- + 3 files changed, 10 insertions(+), 3 deletions(-) + +diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c +index c21a19ab73f7..db2d997a6c18 100644 +--- a/drivers/md/dm-stats.c ++++ b/drivers/md/dm-stats.c +@@ -188,7 +188,7 @@ static int dm_stat_in_flight(struct dm_stat_shared *shared) + atomic_read(&shared->in_flight[WRITE]); + } + +-void dm_stats_init(struct dm_stats *stats) ++int dm_stats_init(struct dm_stats *stats) + { + int cpu; + struct dm_stats_last_position *last; +@@ -197,11 +197,16 @@ void dm_stats_init(struct dm_stats *stats) + INIT_LIST_HEAD(&stats->list); + stats->precise_timestamps = false; + stats->last = alloc_percpu(struct dm_stats_last_position); ++ if (!stats->last) ++ return -ENOMEM; ++ + for_each_possible_cpu(cpu) { + last = per_cpu_ptr(stats->last, cpu); + last->last_sector = (sector_t)ULLONG_MAX; + last->last_rw = UINT_MAX; + } ++ ++ return 0; + } + + void dm_stats_cleanup(struct dm_stats *stats) +diff --git a/drivers/md/dm-stats.h b/drivers/md/dm-stats.h +index 0bc152c8e4f3..c6728c8b4159 100644 +--- a/drivers/md/dm-stats.h ++++ b/drivers/md/dm-stats.h +@@ -21,7 +21,7 @@ struct dm_stats_aux { + unsigned long long duration_ns; + }; + +-void dm_stats_init(struct dm_stats *st); ++int dm_stats_init(struct dm_stats *st); + void dm_stats_cleanup(struct dm_stats *st); + + struct mapped_device; +diff --git a/drivers/md/dm.c b/drivers/md/dm.c +index eace45a18d45..b6ace995b9ca 100644 +--- a/drivers/md/dm.c ++++ b/drivers/md/dm.c +@@ -2097,7 +2097,9 @@ static struct mapped_device *alloc_dev(int minor) + if (!md->pending_io) + goto bad; + +- dm_stats_init(&md->stats); ++ r = dm_stats_init(&md->stats); ++ if (r < 0) ++ goto bad; + + /* Populate the mapping, nobody knows we exist yet */ + spin_lock(&_minor_lock); +-- +2.35.3 + diff --git a/series.conf b/series.conf index 3aa9b06..8028357 100644 --- a/series.conf +++ b/series.conf @@ -40907,6 +40907,7 @@ patches.suse/dm-thin-fix-deadlock-when-swapping-to-thin-device-9bbf.patch patches.suse/dm-crypt-add-cond_resched-to-dmcrypt_write-fb29.patch patches.suse/dm-crypt-avoid-accessing-uninitialized-tasklet-d9a0.patch + patches.suse/dm-stats-check-for-and-propagate-alloc_percpu-failur-d3aa.patch patches.suse/drm-panel-orientation-quirks-Add-quirk-for-Lenovo-Yo.patch patches.suse/drm-meson-fix-missing-component-unbind-on-bind-error.patch patches.suse/drm-bridge-lt8912b-return-EPROBE_DEFER-if-bridge-is-.patch