You've already forked linux-apfs
mirror of
https://github.com/linux-apfs/linux-apfs.git
synced 2026-05-01 15:00:59 -07:00
NFS: Prevent memory allocation failure in nfsacl_encode()
nfsacl_encode() allocates memory in certain cases. This of course
is not guaranteed to work.
Since commit 9f06c719 "SUNRPC: New xdr_streams XDR encoder API", the
kernel's XDR encoders can't return a result indicating possibly a
failure, so a memory allocation failure in nfsacl_encode() has become
fatal (ie, the XDR code Oopses) in some cases.
However, the allocated memory is a tiny fixed amount, on the order
of 40-50 bytes. We can easily use a stack-allocated buffer for
this, with only a wee bit of nose-holding.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
This commit is contained in:
committed by
Trond Myklebust
parent
731f3f482a
commit
f61f6da0d5
+13
-4
@@ -22,6 +22,7 @@
|
||||
|
||||
#include <linux/errno.h>
|
||||
|
||||
EXPORT_SYMBOL(posix_acl_init);
|
||||
EXPORT_SYMBOL(posix_acl_alloc);
|
||||
EXPORT_SYMBOL(posix_acl_clone);
|
||||
EXPORT_SYMBOL(posix_acl_valid);
|
||||
@@ -31,6 +32,16 @@ EXPORT_SYMBOL(posix_acl_create_masq);
|
||||
EXPORT_SYMBOL(posix_acl_chmod_masq);
|
||||
EXPORT_SYMBOL(posix_acl_permission);
|
||||
|
||||
/*
|
||||
* Init a fresh posix_acl
|
||||
*/
|
||||
void
|
||||
posix_acl_init(struct posix_acl *acl, int count)
|
||||
{
|
||||
atomic_set(&acl->a_refcount, 1);
|
||||
acl->a_count = count;
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate a new ACL with the specified number of entries.
|
||||
*/
|
||||
@@ -40,10 +51,8 @@ posix_acl_alloc(int count, gfp_t flags)
|
||||
const size_t size = sizeof(struct posix_acl) +
|
||||
count * sizeof(struct posix_acl_entry);
|
||||
struct posix_acl *acl = kmalloc(size, flags);
|
||||
if (acl) {
|
||||
atomic_set(&acl->a_refcount, 1);
|
||||
acl->a_count = count;
|
||||
}
|
||||
if (acl)
|
||||
posix_acl_init(acl, count);
|
||||
return acl;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user