It is reported that sysfs buffer overflow can be triggered in case
of too many CPU cores(>841 on 4K PAGE_SIZE) when showing CPUs in
blk_mq_hw_sysfs_cpus_show().
So use cpumap_print_to_pagebuf() to print the info and fix the potential
buffer overflow issue.
Cc: stable(a)vger.kernel.org
Cc: Mark Ray <mark.ray(a)hpe.com>
Cc: Greg KH <gregkh(a)linuxfoundation.org>
Fixes: 676141e48af7("blk-mq: don't dump CPU -> hw queue map on driver load")
Signed-off-by: Ming Lei <ming.lei(a)redhat.com>
---
block/blk-mq-sysfs.c | 15 +--------------
1 file changed, 1 insertion(+), 14 deletions(-)
diff --git a/block/blk-mq-sysfs.c b/block/blk-mq-sysfs.c
index d6e1a9bd7131..4d0d32377ba3 100644
--- a/block/blk-mq-sysfs.c
+++ b/block/blk-mq-sysfs.c
@@ -166,20 +166,7 @@ static ssize_t blk_mq_hw_sysfs_nr_reserved_tags_show(struct blk_mq_hw_ctx *hctx,
static ssize_t blk_mq_hw_sysfs_cpus_show(struct blk_mq_hw_ctx *hctx, char *page)
{
- unsigned int i, first = 1;
- ssize_t ret = 0;
-
- for_each_cpu(i, hctx->cpumask) {
- if (first)
- ret += sprintf(ret + page, "%u", i);
- else
- ret += sprintf(ret + page, ", %u", i);
-
- first = 0;
- }
-
- ret += sprintf(ret + page, "\n");
- return ret;
+ return cpumap_print_to_pagebuf(true, page, hctx->cpumask);
}
static struct blk_mq_hw_ctx_sysfs_entry blk_mq_hw_sysfs_nr_tags = {
--
2.20.1
The function kmalloc rather than mempool_alloc is called to allocate
memory when the memory pool is unavailable. However, mempool_alloc is
used to release the memory chunck in both cases when error occurs. This
patch fixes the bug.
Fixes: 9f060e2231c ("block: Convert integrity to bvec_alloc_bs()")
Signed-off-by: Pan Bian <bianpan2016(a)163.com>
Cc: stable(a)vger.kernel.org
---
V2: add Fixes and CC tags
---
block/bio-integrity.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/block/bio-integrity.c b/block/bio-integrity.c
index fb95dbb..011dfc8 100644
--- a/block/bio-integrity.c
+++ b/block/bio-integrity.c
@@ -75,7 +75,10 @@ struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio,
return bip;
err:
- mempool_free(bip, &bs->bio_integrity_pool);
+ if (!bs || !mempool_initialized(&bs->bio_integrity_pool))
+ kfree(bip);
+ else
+ mempool_free(bip, &bs->bio_integrity_pool);
return ERR_PTR(-ENOMEM);
}
EXPORT_SYMBOL(bio_integrity_alloc);
--
2.7.4
The function kmalloc is called to allocate memory if bs is NULL.
However, mempool_free is used to release the memory chunk even if bs is
NULL in the error hanlding code. This patch checks bs and use the
correct function to release memory.
Fixes: 3f86a82aeb ("block: Consolidate bio_alloc_bioset(), bio_kmalloc()")
Signed-off-by: Pan Bian <bianpan2016(a)163.com>
Cc: stable(a)vger.kernel.org
---
V2: add Fixes and Cc tags
---
block/bio.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/block/bio.c b/block/bio.c
index 299a0e7..c5f5238 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -515,7 +515,10 @@ struct bio *bio_alloc_bioset(gfp_t gfp_mask, unsigned int nr_iovecs,
return bio;
err_free:
- mempool_free(p, &bs->bio_pool);
+ if (!bs)
+ kfree(p);
+ else
+ mempool_free(p, &bs->bio_pool);
return NULL;
}
EXPORT_SYMBOL(bio_alloc_bioset);
--
2.7.4