Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp685249pxb; Wed, 11 Nov 2020 13:39:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJz4+5+77cJVq2b12p5OAqbQuWcKkwjVdDgLFoubfpfvR2sQskpIDxkowopVBPADtrMF51JD X-Received: by 2002:a05:6402:31b6:: with SMTP id dj22mr1753550edb.348.1605130784114; Wed, 11 Nov 2020 13:39:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605130784; cv=none; d=google.com; s=arc-20160816; b=Yt2CpEzDDoOCXiGetL4ih7QHz48zQoylRJaYWTyKDffdtANcKQ6/Gmqyl5rSHj3hWG 6XakLXWoNpGP+9hrV/Lf1qOaN2mwNdg382PGpuA2tH6YkqRIm2gxj4Q1YPJWhaFwMwxF 0B7Qry12X6cS4WvF4ukbSGeiQNX8/haChdv5ByKp8lEWaji3VdlZWoVwHROysKm8t7V6 O5iVf3tEz77/0hyl8t5El6nBTizwhb2a8CaLDljn8cIxrbhLBx/AVyhVHswQC4LKxYsG wQwoJhchT+Fswl7pLEdn5zD84hB0F4BVXuNc2+Uia4um2dSGjPQEAYtNTG5Q2r72/Nva wkXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=q5PXtHAxoPUKNf+IoXo9ZFdTmMCuFdttZGJgZ4wQdaM=; b=BY4qvAj0pDbNz4OGrweCEeR90zVxe9hXWDv9jornE5ElKTH00QyABUPRVR98KSM+bc umZX2HBbpsO5xc5NOAEMxaOHU1LsOgKcYbyzwz7+B3S9I88Ot3zj/9DeyTBy3QXgX7TK 1Sglsg0x3IIoyOIC3wYBfFtQGlFmIlJQIfjwQJDse96wK9OkidKn5RuGOQgLYvAkh/wk eut3PqH5YVtAxRV3aOiB4qUNQ65f38DpDjzIZkab6/A1R3jgI1bxCgeAnlQD+Dbsk8RX 4mace7ux8MnWj18hw9n3bgo6tbRwA5FPhWTWCgXstNu1A8r5TQPSnCuoaO3CB7+uUL7P fkJA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b15si2234212eja.538.2020.11.11.13.39.19; Wed, 11 Nov 2020 13:39:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727194AbgKKVew (ORCPT + 99 others); Wed, 11 Nov 2020 16:34:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727121AbgKKVev (ORCPT ); Wed, 11 Nov 2020 16:34:51 -0500 Received: from smtp-190c.mail.infomaniak.ch (smtp-190c.mail.infomaniak.ch [IPv6:2001:1600:4:17::190c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E088AC0617A6 for ; Wed, 11 Nov 2020 13:34:50 -0800 (PST) Received: from smtp-2-0000.mail.infomaniak.ch (unknown [10.5.36.107]) by smtp-3-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4CWdKy1kKxzlhQ42; Wed, 11 Nov 2020 22:34:46 +0100 (CET) Received: from localhost (unknown [94.23.54.103]) by smtp-2-0000.mail.infomaniak.ch (Postfix) with ESMTPA id 4CWdKx6wm5zlh8T4; Wed, 11 Nov 2020 22:34:45 +0100 (CET) From: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= To: James Morris , Jann Horn , "Serge E . Hallyn" Cc: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Shuah Khan , Vincent Dagonneau , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-security-module@vger.kernel.org Subject: [PATCH v1 1/9] landlock: Fix memory allocation error handling Date: Wed, 11 Nov 2020 22:34:34 +0100 Message-Id: <20201111213442.434639-2-mic@digikod.net> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201111213442.434639-1-mic@digikod.net> References: <20201111213442.434639-1-mic@digikod.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Cc: Jann Horn Cc: Serge E. Hallyn Signed-off-by: Mickaël Salaün --- security/landlock/fs.c | 5 +++++ security/landlock/object.c | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/security/landlock/fs.c b/security/landlock/fs.c index d8c5d19ac2af..b67c821bb40b 100644 --- a/security/landlock/fs.c +++ b/security/landlock/fs.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -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); diff --git a/security/landlock/object.c b/security/landlock/object.c index a71644ee72a7..54ba0327002a 100644 --- a/security/landlock/object.c +++ b/security/landlock/object.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -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; -- 2.29.2