@@ -9,6 +9,7 @@
#include <linux/atomic.h>
#include <linux/compiler_types.h>
#include <linux/dcache.h>
+#include <linux/err.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/kernel.h>
@@ -98,6 +99,8 @@ static struct landlock_object *get_inode_object(struct inode *const inode)
* holding any locks).
*/
new_object = landlock_create_object(&landlock_fs_underops, inode);
+ if (IS_ERR(new_object))
+ return new_object;
spin_lock(&inode->i_lock);
object = rcu_dereference_protected(inode_sec->object,
@@ -145,6 +148,8 @@ int landlock_append_fs_rule(struct landlock_ruleset *const ruleset,
access_rights |= _LANDLOCK_ACCESS_FS_MASK & ~ruleset->fs_access_mask;
rule.access = access_rights;
rule.object = get_inode_object(d_backing_inode(path->dentry));
+ if (IS_ERR(rule.object))
+ return PTR_ERR(rule.object);
mutex_lock(&ruleset->lock);
err = landlock_insert_rule(ruleset, &rule, false);
mutex_unlock(&ruleset->lock);
@@ -8,6 +8,7 @@
#include <linux/bug.h>
#include <linux/compiler_types.h>
+#include <linux/err.h>
#include <linux/kernel.h>
#include <linux/rcupdate.h>
#include <linux/refcount.h>
@@ -23,10 +24,10 @@ struct landlock_object *landlock_create_object(
struct landlock_object *new_object;
if (WARN_ON_ONCE(!underops || !underobj))
- return NULL;
+ return ERR_PTR(-ENOENT);
new_object = kzalloc(sizeof(*new_object), GFP_KERNEL_ACCOUNT);
if (!new_object)
- return NULL;
+ return ERR_PTR(-ENOMEM);
refcount_set(&new_object->usage, 1);
spin_lock_init(&new_object->lock);
new_object->underops = underops;
Handle memory allocation errors in landlock_create_object() call. This prevent to inadvertently hold an inode. Also, make get_inode_object() more readable. Cc: James Morris <jmorris@namei.org> Cc: Jann Horn <jannh@google.com> Cc: Serge E. Hallyn <serge@hallyn.com> Signed-off-by: Mickaël Salaün <mic@digikod.net> --- security/landlock/fs.c | 5 +++++ security/landlock/object.c | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-)