Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 607566ae authored by Josh Boyer's avatar Josh Boyer Committed by Linus Torvalds
Browse files

CacheFiles: Fix memory leak in cachefiles_check_auxdata error paths



In cachefiles_check_auxdata(), we allocate auxbuf but fail to free it if
we determine there's an error or that the data is stale.

Further, assigning the output of vfs_getxattr() to auxbuf->len gives
problems with checking for errors as auxbuf->len is a u16.  We don't
actually need to set auxbuf->len, so keep the length in a variable for
now.  We shouldn't need to check the upper limit of the buffer as an
overflow there should be indicated by -ERANGE.

While we're at it, fscache_check_aux() returns an enum value, not an
int, so assign it to an appropriately typed variable rather than to ret.

Signed-off-by: default avatarJosh Boyer <jwboyer@fedoraproject.org>
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
cc: Hongyi Jia <jiayisuse@gmail.com>
cc: Milosz Tanski <milosz@adfin.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 8f4c3446
Loading
Loading
Loading
Loading
+15 −14
Original line number Original line Diff line number Diff line
@@ -162,8 +162,9 @@ int cachefiles_update_object_xattr(struct cachefiles_object *object,
int cachefiles_check_auxdata(struct cachefiles_object *object)
int cachefiles_check_auxdata(struct cachefiles_object *object)
{
{
	struct cachefiles_xattr *auxbuf;
	struct cachefiles_xattr *auxbuf;
	enum fscache_checkaux validity;
	struct dentry *dentry = object->dentry;
	struct dentry *dentry = object->dentry;
	unsigned int dlen;
	ssize_t xlen;
	int ret;
	int ret;


	ASSERT(dentry);
	ASSERT(dentry);
@@ -174,22 +175,22 @@ int cachefiles_check_auxdata(struct cachefiles_object *object)
	if (!auxbuf)
	if (!auxbuf)
		return -ENOMEM;
		return -ENOMEM;


	auxbuf->len = vfs_getxattr(dentry, cachefiles_xattr_cache,
	xlen = vfs_getxattr(dentry, cachefiles_xattr_cache,
			    &auxbuf->type, 512 + 1);
			    &auxbuf->type, 512 + 1);
	if (auxbuf->len < 1)
	ret = -ESTALE;
		return -ESTALE;
	if (xlen < 1 ||

	    auxbuf->type != object->fscache.cookie->def->type)
	if (auxbuf->type != object->fscache.cookie->def->type)
		goto error;
		return -ESTALE;


	dlen = auxbuf->len - 1;
	xlen--;
	ret = fscache_check_aux(&object->fscache, &auxbuf->data, dlen);
	validity = fscache_check_aux(&object->fscache, &auxbuf->data, xlen);
	if (validity != FSCACHE_CHECKAUX_OKAY)
		goto error;


	ret = 0;
error:
	kfree(auxbuf);
	kfree(auxbuf);
	if (ret != FSCACHE_CHECKAUX_OKAY)
	return ret;
		return -ESTALE;

	return 0;
}
}


/*
/*