From 8a1d9a2f06a984bb061949bb57f0941f405c5660 Mon Sep 17 00:00:00 2001 From: Jeffle Xu Date: Thu, 24 Dec 2020 19:46:17 +0800 Subject: [PATCH 2527/2944] alinux: dm crypt: fix sysfs name collision when reloading table fix #32492168 The table reload routine will create new table, with the old table preserved. In this case, the duplicate name collision will happen when creating the sysfs directory for the workqueue of the newly created table, since the old table has not been destroyed at that time. One workaround for this issue is to add unique hash string to the name of the sysfs directory. The value of dm_target pointer is used to generate the hash. This commit also fixes one hidden bug. Prior to this commit, 'devname' is used to compensate the name of the workqueue. 'devname' represents the name of the mapped device, such as '253:0', so there will be name collision if one mapped device corresponds to multiple target devices. Since currently a string hashed from dm_target pointer is added to the name, different target device will have unique name now. Since then, the exported sysfs directory will be named like 'kcryptd-252:0-3a512302'. It is worth noting that some details need to be handled specifically. The %p format of printk will print a hexadecimal string after hashing. In 64-bit architecture, the output will be 16 bytes long, with the previous 8 bytes zeroed, such as '00000000abcdef12'. Since the length of the name of workqueue is limited to WQ_NAME_LEN, i.e. 24 bytes, the previous 8 bytes zeroed need to be discarded. Reported-by: Ignat Korchagin Fixes: a2b8b2d97567 ("dm crypt: export sysfs of kcryptd workqueue") Signed-off-by: Jeffle Xu Reviewed-by: Joseph Qi --- drivers/md/dm-crypt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index f9e249d..62895f0 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -2833,10 +2833,11 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) cc->crypt_queue = alloc_workqueue("kcryptd-%s", WQ_CPU_INTENSIVE | WQ_MEM_RECLAIM, 1, devname); else - cc->crypt_queue = alloc_workqueue("kcryptd-%s", + cc->crypt_queue = alloc_workqueue("kcryptd-%s-%08p", WQ_CPU_INTENSIVE | WQ_MEM_RECLAIM | WQ_UNBOUND | WQ_SYSFS, - num_online_cpus(), devname); + num_online_cpus(), devname, ti); + if (!cc->crypt_queue) { ti->error = "Couldn't create kcryptd queue"; goto bad; -- 1.8.3.1