From: Wang Yan <wangyan01@kylinos.cn>
To: linux-security-module@vger.kernel.org
Cc: paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com,
shuah@kernel.org, casey@schaufler-ca.com, mic@digikod.net,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
Wang Yan <wangyan01@kylinos.cn>
Subject: [PATCH] selftests/lsm: Fix memory leak in attr_lsm_count
Date: Fri, 3 Jul 2026 10:52:47 +0800 [thread overview]
Message-ID: <20260703025247.940055-1-wangyan01@kylinos.cn> (raw)
The calloc-allocated buffer in attr_lsm_count() is never released on
any exit path, including both the normal return path and the early
return when read_sysfs_lsms fails, resulting in a heap memory leak.
Add free() for the buffer on all return branches to fix the leak.
Fixes: d3d929a8b0cd ("LSM: selftests for Linux Security Module syscalls")
Signed-off-by: Wang Yan <wangyan01@kylinos.cn>
---
tools/testing/selftests/lsm/common.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tools/testing/selftests/lsm/common.c b/tools/testing/selftests/lsm/common.c
index 9ad258912646..4fa8310750a0 100644
--- a/tools/testing/selftests/lsm/common.c
+++ b/tools/testing/selftests/lsm/common.c
@@ -76,6 +76,7 @@ int attr_lsm_count(void)
return 0;
if (read_sysfs_lsms(names, sysconf(_SC_PAGESIZE)))
+ free(names);
return 0;
if (strstr(names, "selinux"))
@@ -85,5 +86,6 @@ int attr_lsm_count(void)
if (strstr(names, "apparmor"))
count++;
+ free(names);
return count;
}
--
2.25.1
next reply other threads:[~2026-07-03 2:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-03 2:52 Wang Yan [this message]
2026-07-03 3:01 ` [PATCH] selftests/lsm: Fix memory leak in attr_lsm_count William Roberts
2026-07-03 12:09 ` [PATCH v2] " Wang Yan
2026-07-03 17:56 ` William Roberts
2026-07-07 19:13 ` Paul Moore
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260703025247.940055-1-wangyan01@kylinos.cn \
--to=wangyan01@kylinos.cn \
--cc=casey@schaufler-ca.com \
--cc=jmorris@namei.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=mic@digikod.net \
--cc=paul@paul-moore.com \
--cc=serge@hallyn.com \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox