Skip to contentSkip to conversation

posix_acl: fix memleak when set posix acl.

PATCH Superseded Zhang Xiaoxu 1 participant 1 message Nov 26, 2019 VFS

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 posix_acl: fix memleak when set posix acl.

When set posix acl, it maybe call posix_acl_update_mode in some filesystem, eg. ext4. It may set acl to NULL, so, we can't free the acl which allocated in posix_acl_xattr_set.

Use an temp value to store the acl address for posix_acl_release.

---
 fs/posix_acl.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
fs/posix_acl.c +7 -2
index 84ad1c90d535..b90902d7e6ad 100644
@@ -882,7 +882,7 @@ posix_acl_xattr_set(const struct xattr_handler *handler,
 		    const char *name, const void *value,
 		    size_t size, int flags)
 {
-	struct posix_acl *acl = NULL;
+	struct posix_acl *acl = NULL, *p = NULL;
 	int ret;
 
 	if (value) {
@@ -890,8 +890,13 @@ posix_acl_xattr_set(const struct xattr_handler *handler,
 		if (IS_ERR(acl))
 			return PTR_ERR(acl);
 	}
+
+	/* when call set_posix_acl, posix_acl_update_mode may set acl to NULL,
+	   use temporary variables p for posix_acl_release. */
+	p = acl;
 	ret = set_posix_acl(inode, handler->flags, acl);
-	posix_acl_release(acl);
+
+	posix_acl_release(p);
 	return ret;
 }
 
Signature · 1 line
2.17.2