Mirsad Goran Todorovac
48e1560230
test_firmware: fix the memory leak of the allocated firmware buffer
The following kernel memory leak was noticed after running
tools/testing/selftests/firmware/fw_run_tests.sh:
[root@pc-mtodorov firmware]# cat /sys/kernel/debug/kmemleak
.
.
.
unreferenced object 0xffff955389bc3400 (size 1024):
comm "test_firmware-0", pid 5451, jiffies 4294944822 (age 65.652s)
hex dump (first 32 bytes):
47 48 34 35 36 37 0a 00 00 00 00 00 00 00 00 00 GH4567..........
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
backtrace:
[<ffffffff962f5dec>] slab_post_alloc_hook+0x8c/0x3c0
[<ffffffff962fcca4>] __kmem_cache_alloc_node+0x184/0x240
[<ffffffff962704de>] kmalloc_trace+0x2e/0xc0
[<ffffffff9665b42d>] test_fw_run_batch_request+0x9d/0x180
[<ffffffff95fd813b>] kthread+0x10b/0x140
[<ffffffff95e033e9>] ret_from_fork+0x29/0x50
unreferenced object 0xffff9553c334b400 (size 1024):
comm "test_firmware-1", pid 5452, jiffies 4294944822 (age 65.652s)
hex dump (first 32 bytes):
47 48 34 35 36 37 0a 00 00 00 00 00 00 00 00 00 GH4567..........
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
backtrace:
[<ffffffff962f5dec>] slab_post_alloc_hook+0x8c/0x3c0
[<ffffffff962fcca4>] __kmem_cache_alloc_node+0x184/0x240
[<ffffffff962704de>] kmalloc_trace+0x2e/0xc0
[<ffffffff9665b42d>] test_fw_run_batch_request+0x9d/0x180
[<ffffffff95fd813b>] kthread+0x10b/0x140
[<ffffffff95e033e9>] ret_from_fork+0x29/0x50
unreferenced object 0xffff9553c334f000 (size 1024):
comm "test_firmware-2", pid 5453, jiffies 4294944822 (age 65.652s)
hex dump (first 32 bytes):
47 48 34 35 36 37 0a 00 00 00 00 00 00 00 00 00 GH4567..........
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
backtrace:
[<ffffffff962f5dec>] slab_post_alloc_hook+0x8c/0x3c0
[<ffffffff962fcca4>] __kmem_cache_alloc_node+0x184/0x240
[<ffffffff962704de>] kmalloc_trace+0x2e/0xc0
[<ffffffff9665b42d>] test_fw_run_batch_request+0x9d/0x180
[<ffffffff95fd813b>] kthread+0x10b/0x140
[<ffffffff95e033e9>] ret_from_fork+0x29/0x50
unreferenced object 0xffff9553c3348400 (size 1024):
comm "test_firmware-3", pid 5454, jiffies 4294944822 (age 65.652s)
hex dump (first 32 bytes):
47 48 34 35 36 37 0a 00 00 00 00 00 00 00 00 00 GH4567..........
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
backtrace:
[<ffffffff962f5dec>] slab_post_alloc_hook+0x8c/0x3c0
[<ffffffff962fcca4>] __kmem_cache_alloc_node+0x184/0x240
[<ffffffff962704de>] kmalloc_trace+0x2e/0xc0
[<ffffffff9665b42d>] test_fw_run_batch_request+0x9d/0x180
[<ffffffff95fd813b>] kthread+0x10b/0x140
[<ffffffff95e033e9>] ret_from_fork+0x29/0x50
[root@pc-mtodorov firmware]#
Note that the size 1024 corresponds to the size of the test firmware
buffer. The actual number of the buffers leaked is around 70-110,
depending on the test run.
The cause of the leak is the following:
request_partial_firmware_into_buf() and request_firmware_into_buf()
provided firmware buffer isn't released on release_firmware(), we
have allocated it and we are responsible for deallocating it manually.
This is introduced in a number of context where previously only
release_firmware() was called, which was insufficient.
Reported-by: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr>
Fixes: 7feebfa487 ("test_firmware: add support for request_firmware_into_buf")
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Dan Carpenter <error27@gmail.com>
Cc: Takashi Iwai <tiwai@suse.de>
Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: Russ Weight <russell.h.weight@intel.com>
Cc: Tianfei zhang <tianfei.zhang@intel.com>
Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: Zhengchao Shao <shaozhengchao@huawei.com>
Cc: Colin Ian King <colin.i.king@gmail.com>
Cc: linux-kernel@vger.kernel.org
Cc: Kees Cook <keescook@chromium.org>
Cc: Scott Branden <sbranden@broadcom.com>
Cc: Luis R. Rodriguez <mcgrof@kernel.org>
Cc: linux-kselftest@vger.kernel.org
Cc: stable@vger.kernel.org # v5.4
Signed-off-by: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr>
Link: https://lore.kernel.org/r/20230509084746.48259-3-mirsad.todorovac@alu.unizg.hr
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-05-31 20:31:07 +01:00
..
2023-04-27 16:36:55 -07:00
2023-05-09 11:06:45 +02:00
2023-04-05 12:51:30 -06:00
2023-01-06 17:15:46 +08:00
2023-04-13 13:13:53 -07:00
2022-12-13 10:43:59 -08:00
2023-03-21 21:15:34 +01:00
2023-02-27 17:00:14 -08:00
2023-02-02 22:50:10 -08:00
2023-02-02 22:50:09 -08:00
2023-03-06 15:54:54 -08:00
2023-04-13 13:13:54 -07:00
2023-01-31 15:01:45 +01:00
2023-04-08 13:45:37 -07:00
2023-03-24 16:04:21 -07:00
2023-03-05 14:30:34 -08:00
2023-02-07 18:20:00 -08:00
2023-05-22 14:52:58 +02:00
2023-01-31 20:37:18 +01:00
2023-02-02 22:50:01 -08:00
2023-02-02 22:50:01 -08:00
2023-03-23 17:18:35 -07:00
2023-02-02 22:50:01 -08:00
2023-03-09 12:58:36 -08:00
2023-02-15 15:44:43 +01:00
2023-02-02 22:50:00 -08:00
2023-04-13 07:38:54 -06:00
2023-03-19 10:02:04 -07:00
2023-02-02 22:50:05 -08:00
2023-04-21 03:02:31 -04:00
2023-02-08 14:28:17 -07:00
2023-05-02 17:21:50 -07:00
2023-04-05 22:15:19 +02:00
2023-04-30 11:43:31 -07:00
2023-03-02 21:54:22 -08:00
2023-02-25 13:02:20 -08:00
2023-03-17 15:15:23 +01:00
2023-04-17 18:01:23 +02:00
2023-03-31 09:21:35 -06:00
2023-01-13 14:35:38 -06:00
2023-04-27 16:36:55 -07:00
2023-05-17 15:24:32 -07:00
2023-01-25 12:24:40 -08:00
2023-01-20 17:52:32 -08:00
2023-01-19 15:55:12 -08:00
2023-03-09 23:08:04 -08:00
2023-03-02 21:54:22 -08:00
2023-03-19 10:02:04 -07:00
2023-04-18 16:39:33 -07:00
2023-03-28 10:39:29 +02:00
2023-01-29 20:03:01 -07:00
2023-01-16 12:08:31 -04:00
2023-04-25 21:03:14 -04:00
2023-04-21 14:52:02 -07:00
2022-12-12 16:42:57 -08:00
2023-03-28 16:20:13 -07:00
2023-02-10 17:32:37 -08:00
2023-01-27 11:42:57 -08:00
2023-05-31 20:31:07 +01:00
2023-04-28 15:57:53 -07:00
2023-01-25 14:07:21 -08:00
2023-02-21 08:52:42 +09:00
2023-03-23 17:18:32 -07:00
2023-03-28 16:20:09 -07:00
2022-12-13 15:47:48 -08:00
2023-04-27 19:42:02 -07:00
2023-04-08 13:45:39 -07:00
2023-02-21 11:07:23 -08:00
2023-02-08 15:26:58 -08:00
2023-02-21 14:45:22 -08:00
2023-04-27 19:42:02 -07:00
2023-01-11 16:14:21 -08:00