Skip to content

Commit bf42dae

Browse files
efarmancohuck
authored andcommitted
s390/cio: Refactor alloc of ccw_io_region
If I attach a vfio-ccw device to my guest, I get the following warning on the host when the host kernel is CONFIG_HARDENED_USERCOPY=y [250757.595325] Bad or missing usercopy whitelist? Kernel memory overwrite attempt detected to SLUB object 'dma-kmalloc-512' (offset 64, size 124)! [250757.595365] WARNING: CPU: 2 PID: 10958 at mm/usercopy.c:81 usercopy_warn+0xac/0xd8 [250757.595369] Modules linked in: kvm vhost_net vhost tap xt_CHECKSUM iptable_mangle ipt_MASQUERADE iptable_nat nf_nat_ipv4 nf_nat nf_conntrack_ipv4 nf_defrag_ipv4 xt_conntrack nf_conntrack libcrc32c devlink tun bridge stp llc ebtable_filter ebtables ip6table_filter ip6_tables sunrpc dm_multipath s390_trng crc32_vx_s390 ghash_s390 prng aes_s390 des_s390 des_generic sha512_s390 sha1_s390 eadm_sch tape_3590 tape tape_class qeth_l2 qeth ccwgroup vfio_ccw vfio_mdev zcrypt_cex4 mdev vfio_iommu_type1 zcrypt vfio sha256_s390 sha_common zfcp scsi_transport_fc qdio dasd_eckd_mod dasd_mod [250757.595424] CPU: 2 PID: 10958 Comm: CPU 2/KVM Not tainted 4.18.0-derp #2 [250757.595426] Hardware name: IBM 3906 M05 780 (LPAR) ...snip regs... [250757.595523] Call Trace: [250757.595529] ([<0000000000349210>] usercopy_warn+0xa8/0xd8) [250757.595535] [<000000000032daaa>] __check_heap_object+0xfa/0x160 [250757.595540] [<0000000000349396>] __check_object_size+0x156/0x1d0 [250757.595547] [<000003ff80332d04>] vfio_ccw_mdev_write+0x74/0x148 [vfio_ccw] [250757.595552] [<000000000034ed12>] __vfs_write+0x3a/0x188 [250757.595556] [<000000000034f040>] vfs_write+0xa8/0x1b8 [250757.595559] [<000000000034f4e6>] ksys_pwrite64+0x86/0xc0 [250757.595568] [<00000000008959a0>] system_call+0xdc/0x2b0 [250757.595570] Last Breaking-Event-Address: [250757.595573] [<0000000000349210>] usercopy_warn+0xa8/0xd8 While vfio_ccw_mdev_{write|read} validates that the input position/count does not run over the ccw_io_region struct, the usercopy code that does copy_{to|from}_user doesn't necessarily know this. It sees the variable length and gets worried that it's affecting a normal kmalloc'd struct, and generates the above warning. Adjust how the ccw_io_region is alloc'd with a whitelist to remove this warning. The boundary checking will continue to do its thing. Signed-off-by: Eric Farman <[email protected]> Message-Id: <[email protected]> Signed-off-by: Cornelia Huck <[email protected]>
1 parent c98e16b commit bf42dae

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

drivers/s390/cio/vfio_ccw_drv.c

+16-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "vfio_ccw_private.h"
2323

2424
struct workqueue_struct *vfio_ccw_work_q;
25+
struct kmem_cache *vfio_ccw_io_region;
2526

2627
/*
2728
* Helpers
@@ -115,8 +116,8 @@ static int vfio_ccw_sch_probe(struct subchannel *sch)
115116
if (!private)
116117
return -ENOMEM;
117118

118-
private->io_region = kzalloc(sizeof(*private->io_region),
119-
GFP_KERNEL | GFP_DMA);
119+
private->io_region = kmem_cache_zalloc(vfio_ccw_io_region,
120+
GFP_KERNEL | GFP_DMA);
120121
if (!private->io_region) {
121122
kfree(private);
122123
return -ENOMEM;
@@ -147,7 +148,7 @@ static int vfio_ccw_sch_probe(struct subchannel *sch)
147148
cio_disable_subchannel(sch);
148149
out_free:
149150
dev_set_drvdata(&sch->dev, NULL);
150-
kfree(private->io_region);
151+
kmem_cache_free(vfio_ccw_io_region, private->io_region);
151152
kfree(private);
152153
return ret;
153154
}
@@ -162,7 +163,7 @@ static int vfio_ccw_sch_remove(struct subchannel *sch)
162163

163164
dev_set_drvdata(&sch->dev, NULL);
164165

165-
kfree(private->io_region);
166+
kmem_cache_free(vfio_ccw_io_region, private->io_region);
166167
kfree(private);
167168

168169
return 0;
@@ -242,10 +243,20 @@ static int __init vfio_ccw_sch_init(void)
242243
if (!vfio_ccw_work_q)
243244
return -ENOMEM;
244245

246+
vfio_ccw_io_region = kmem_cache_create_usercopy("vfio_ccw_io_region",
247+
sizeof(struct ccw_io_region), 0,
248+
SLAB_ACCOUNT, 0,
249+
sizeof(struct ccw_io_region), NULL);
250+
if (!vfio_ccw_io_region) {
251+
destroy_workqueue(vfio_ccw_work_q);
252+
return -ENOMEM;
253+
}
254+
245255
isc_register(VFIO_CCW_ISC);
246256
ret = css_driver_register(&vfio_ccw_sch_driver);
247257
if (ret) {
248258
isc_unregister(VFIO_CCW_ISC);
259+
kmem_cache_destroy(vfio_ccw_io_region);
249260
destroy_workqueue(vfio_ccw_work_q);
250261
}
251262

@@ -256,6 +267,7 @@ static void __exit vfio_ccw_sch_exit(void)
256267
{
257268
css_driver_unregister(&vfio_ccw_sch_driver);
258269
isc_unregister(VFIO_CCW_ISC);
270+
kmem_cache_destroy(vfio_ccw_io_region);
259271
destroy_workqueue(vfio_ccw_work_q);
260272
}
261273
module_init(vfio_ccw_sch_init);

0 commit comments

Comments
 (0)