]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
kselftests: cgroup: Avoid the reuse of fd after it is deallocated
authorHewenliang <hewenliang4@huawei.com>
Tue, 12 Nov 2019 02:16:55 +0000 (21:16 -0500)
committerPaolo Pisati <paolo.pisati@canonical.com>
Thu, 30 Jan 2020 15:27:38 +0000 (16:27 +0100)
BugLink: https://bugs.launchpad.net/bugs/1861091
[ Upstream commit d671fa6393d6788fc65555d4643b71cb3a361f36 ]

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>
Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
tools/testing/selftests/cgroup/test_freezer.c

index 0fc1b6d4b0f9c4db9084158fd22b755e7b53482f..62a27ab3c2f3edb7b06137f736c118832e860c19 100644 (file)
@@ -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;