lists.openwall.net | lists / announce owl-users owl-dev john-users john-dev passwdqc-users yescrypt popa3d-users / oss-security kernel-hardening musl sabotage tlsify passwords / crypt-dev xvendor / Bugtraq Full-Disclosure linux-kernel linux-netdev linux-ext4 linux-hardening linux-cve-announce PHC | |
Open Source and information security mailing list archives
| ||
|
Message-ID: <20171212144506.c4z6aqieo5uo3pcn@lakrids.cambridge.arm.com> Date: Tue, 12 Dec 2017 14:45:07 +0000 From: Mark Rutland <mark.rutland@....com> To: weiping zhang <zwp10758@...il.com> Cc: linux-kernel@...r.kernel.org, Cornelia Huck <cohuck@...hat.com>, weiping zhang <zhangweiping@...ichuxing.com>, virtualization@...ts.linux-foundation.org, "Michael S . Tsirkin" <mst@...hat.com> Subject: Re: [PATCHv2] virtio_mmio: fix devm cleanup On Tue, Dec 12, 2017 at 10:26:24PM +0800, weiping zhang wrote: > 2017-12-12 21:45 GMT+08:00 Mark Rutland <mark.rutland@....com>: > Hi Mark, Hi, > thanks your patch, I dig into these three devm_xxx funciton, > all of them represented by a struct devres as following, > > struct devres_node { > struct list_head entry; > dr_release_t release; > #ifdef CONFIG_DEBUG_DEVRES > const char *name; > size_t size; > #endif > > }; > > struct devres { > struct devres_node node; > /* -- 3 pointers */ > unsigned long long data[]; /* guarantee ull alignment */ > }; > 2) devm_kzalloc -> devm_kmalloc > > dr = alloc_dr(devm_kmalloc_release, size, gfp, dev_to_node(dev)); > "devm_kmalloc_release" is noop, do nothing. Please note that the release function is there to perform cleanup prior to the devm infrastructure releasing the memory. The devm_kmalloc_release function is a no-op since nothing has to be done prior to memory being freed, but the memory itself is still freed. In alloc_dr(), the struct devres is allocated together with the memory, since alloc_dr() does: size_t tot_size = sizeof(struct devres) + size; struct devres *dr; dr = kmalloc_node_track_caller(tot_size, gfp, nid); return dr->data; ... where dr->data points at the memory after the struct devres. Later, in release_nodes() we do: list_for_each_entry_safe_reverse(dr, tmp, &todo, node.entry) { devres_log(dev, &dr->node, "REL"); dr->node.release(dev, dr->data); kfree(dr); } ... which will invoke the no-op devm_kmalloc_release, then free the devres allocation, including the dr->data memory the user requested. > so for case 2) above, we need a devm_kfree() before call > register_virtio_device As above, I do not believe that is the case. Thanks, Mark.
Powered by blists - more mailing lists