Skip to content

Commit 4d7b04c

Browse files
committed
Merge tag 's390-6.6-4' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux
Pull s390 fixes from Vasily Gorbik: - Fix IOMMU bitmap allocation in s390 PCI to avoid out of bounds access when IOMMU pages aren't a multiple of 64 - Fix kasan crashes when accessing DCSS mapping in memory holes by adding corresponding kasan zero shadow mappings - Fix a memory leak in css_alloc_subchannel in case dma_set_coherent_mask fails * tag 's390-6.6-4' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux: s390/pci: fix iommu bitmap allocation s390/kasan: handle DCSS mapping in memory holes s390/cio: fix a memleak in css_alloc_subchannel
2 parents f51de61 + c1ae1c5 commit 4d7b04c

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

arch/s390/boot/vmem.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ static void kasan_populate_shadow(void)
5757
pmd_t pmd_z = __pmd(__pa(kasan_early_shadow_pte) | _SEGMENT_ENTRY);
5858
pud_t pud_z = __pud(__pa(kasan_early_shadow_pmd) | _REGION3_ENTRY);
5959
p4d_t p4d_z = __p4d(__pa(kasan_early_shadow_pud) | _REGION2_ENTRY);
60+
unsigned long memgap_start = 0;
6061
unsigned long untracked_end;
6162
unsigned long start, end;
6263
int i;
@@ -101,8 +102,12 @@ static void kasan_populate_shadow(void)
101102
* +- shadow end ----+---------+- shadow end ---+
102103
*/
103104

104-
for_each_physmem_usable_range(i, &start, &end)
105+
for_each_physmem_usable_range(i, &start, &end) {
105106
kasan_populate(start, end, POPULATE_KASAN_MAP_SHADOW);
107+
if (memgap_start && physmem_info.info_source == MEM_DETECT_DIAG260)
108+
kasan_populate(memgap_start, start, POPULATE_KASAN_ZERO_SHADOW);
109+
memgap_start = end;
110+
}
106111
if (IS_ENABLED(CONFIG_KASAN_VMALLOC)) {
107112
untracked_end = VMALLOC_START;
108113
/* shallowly populate kasan shadow for vmalloc and modules */

arch/s390/pci/pci_dma.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,17 @@ static void s390_dma_unmap_sg(struct device *dev, struct scatterlist *sg,
564564
s->dma_length = 0;
565565
}
566566
}
567+
568+
static unsigned long *bitmap_vzalloc(size_t bits, gfp_t flags)
569+
{
570+
size_t n = BITS_TO_LONGS(bits);
571+
size_t bytes;
572+
573+
if (unlikely(check_mul_overflow(n, sizeof(unsigned long), &bytes)))
574+
return NULL;
575+
576+
return vzalloc(bytes);
577+
}
567578

568579
int zpci_dma_init_device(struct zpci_dev *zdev)
569580
{
@@ -604,13 +615,13 @@ int zpci_dma_init_device(struct zpci_dev *zdev)
604615
zdev->end_dma - zdev->start_dma + 1);
605616
zdev->end_dma = zdev->start_dma + zdev->iommu_size - 1;
606617
zdev->iommu_pages = zdev->iommu_size >> PAGE_SHIFT;
607-
zdev->iommu_bitmap = vzalloc(zdev->iommu_pages / 8);
618+
zdev->iommu_bitmap = bitmap_vzalloc(zdev->iommu_pages, GFP_KERNEL);
608619
if (!zdev->iommu_bitmap) {
609620
rc = -ENOMEM;
610621
goto free_dma_table;
611622
}
612623
if (!s390_iommu_strict) {
613-
zdev->lazy_bitmap = vzalloc(zdev->iommu_pages / 8);
624+
zdev->lazy_bitmap = bitmap_vzalloc(zdev->iommu_pages, GFP_KERNEL);
614625
if (!zdev->lazy_bitmap) {
615626
rc = -ENOMEM;
616627
goto free_bitmap;

drivers/s390/cio/css.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,17 +233,19 @@ struct subchannel *css_alloc_subchannel(struct subchannel_id schid,
233233
*/
234234
ret = dma_set_coherent_mask(&sch->dev, DMA_BIT_MASK(31));
235235
if (ret)
236-
goto err;
236+
goto err_lock;
237237
/*
238238
* But we don't have such restrictions imposed on the stuff that
239239
* is handled by the streaming API.
240240
*/
241241
ret = dma_set_mask(&sch->dev, DMA_BIT_MASK(64));
242242
if (ret)
243-
goto err;
243+
goto err_lock;
244244

245245
return sch;
246246

247+
err_lock:
248+
kfree(sch->lock);
247249
err:
248250
kfree(sch);
249251
return ERR_PTR(ret);

0 commit comments

Comments
 (0)