linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kselftests: cgroup: Avoid the reuse of fd after it is deallocated
@ 2019-11-12  2:16 Hewenliang
  2019-11-12 15:35 ` Tejun Heo
  0 siblings, 1 reply; 2+ messages in thread
From: Hewenliang @ 2019-11-12  2:16 UTC (permalink / raw)
  To: shuah, tj, guro, linux-kselftest, linux-kernel

It is necessary to set fd to -1 when inotify_add_watch() fails in
cg_prepare_for_wait. Otherwise the fd which has been closed in
cg_prepare_for_wait may be misused in other functions such as
cg_enter_and_wait_for_frozen and cg_freeze_wait.

Fixes: 5313bfe425c8 ("selftests: cgroup: add freezer controller self-tests")
Signed-off-by: Hewenliang <hewenliang4@huawei.com>
---
 tools/testing/selftests/cgroup/test_freezer.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/cgroup/test_freezer.c b/tools/testing/selftests/cgroup/test_freezer.c
index 0fc1b6d4b0f9..62a27ab3c2f3 100644
--- a/tools/testing/selftests/cgroup/test_freezer.c
+++ b/tools/testing/selftests/cgroup/test_freezer.c
@@ -72,6 +72,7 @@ static int cg_prepare_for_wait(const char *cgroup)
 	if (ret == -1) {
 		debug("Error: inotify_add_watch() failed\n");
 		close(fd);
+		fd = -1;
 	}
 
 	return fd;
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] kselftests: cgroup: Avoid the reuse of fd after it is deallocated
  2019-11-12  2:16 [PATCH] kselftests: cgroup: Avoid the reuse of fd after it is deallocated Hewenliang
@ 2019-11-12 15:35 ` Tejun Heo
  0 siblings, 0 replies; 2+ messages in thread
From: Tejun Heo @ 2019-11-12 15:35 UTC (permalink / raw)
  To: Hewenliang; +Cc: shuah, guro, linux-kselftest, linux-kernel

On Mon, Nov 11, 2019 at 09:16:55PM -0500, Hewenliang wrote:
> It is necessary to set fd to -1 when inotify_add_watch() fails in
> cg_prepare_for_wait. Otherwise the fd which has been closed in
> cg_prepare_for_wait may be misused in other functions such as
> cg_enter_and_wait_for_frozen and cg_freeze_wait.
> 
> Fixes: 5313bfe425c8 ("selftests: cgroup: add freezer controller self-tests")
> Signed-off-by: Hewenliang <hewenliang4@huawei.com>

Applied to cgroup/for-5.5.

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-11-12 15:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-12  2:16 [PATCH] kselftests: cgroup: Avoid the reuse of fd after it is deallocated Hewenliang
2019-11-12 15:35 ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).