Skip to content

Commit

Permalink
staging: gasket: Fix mapping refcnt leak when put attribute fails
Browse files Browse the repository at this point in the history
[ Upstream commit 57a6683 ]

gasket_sysfs_put_attr() invokes get_mapping(), which returns a reference
of the specified gasket_sysfs_mapping object to "mapping" with increased
refcnt.

When gasket_sysfs_put_attr() returns, local variable "mapping" becomes
invalid, so the refcount should be decreased to keep refcount balanced.

The reference counting issue happens in one path of
gasket_sysfs_put_attr(). When mapping attribute is unknown, the function
forgets to decrease the refcnt increased by get_mapping(), causing a
refcnt leak.

Fix this issue by calling put_mapping() when put attribute fails due to
unknown attribute.

Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
Link: https://lore.kernel.org/r/1587618895-13660-1-git-send-email-xiyuyang19@fudan.edu.cn
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Xiyu Yang authored and Greg Kroah-Hartman committed Jun 24, 2020
1 parent 0c884f3 commit b3b4dcd
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions drivers/staging/gasket/gasket_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ void gasket_sysfs_put_attr(struct device *device,

dev_err(device, "Unable to put unknown attribute: %s\n",
attr->attr.attr.name);
put_mapping(mapping);
}
EXPORT_SYMBOL(gasket_sysfs_put_attr);

Expand Down

0 comments on commit b3b4dcd

Please sign in to comment.