From patchwork Thu Jan 27 16:51:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 12727091 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F65EC43217 for ; Thu, 27 Jan 2022 16:51:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244124AbiA0Qvw (ORCPT ); Thu, 27 Jan 2022 11:51:52 -0500 Received: from sonic301-38.consmr.mail.ne1.yahoo.com ([66.163.184.207]:35274 "EHLO sonic301-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244126AbiA0Qvv (ORCPT ); Thu, 27 Jan 2022 11:51:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1643302311; bh=M2Qlk9REGuhjYaBELfE5YlmJbpyQZ6U9Mho8iiCcp70=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From:Subject:Reply-To; b=MjTPPkq2xweAHiAOc9ukbMGOKI3t0Fv2W5dfkdTyUnOh1TTHDzNkqtC5WCkpEBtMdGwNWZ4j8i55K4JyJu2HQ/2Qr/87qnDgAueQGojaWCjzEqpgbtfSjqMwWIcgIRaCeTtzG4ZqVOwHZjHDldzh3yxzPUS7ESxY49tSGjYtYwoe5IM+90j27n29roJu31j8CyzrGxBUQ/K0OKSD0L88GgPziPS5wLoTTKOk817TELfms18mrReu6/4XX0TkXLC+P1UJ/2W5fssRGaY1oIpt+aXLW1eA9+5sEYho9YyeZKo9B3ESiigtn5bA1fWZn44tuiyC9dlERddFaQJV8O053Q== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s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wz.T9ZcYLeoQapPjBoh9ahr.HmtuuakWsUV qtes2ULTAt_nlDJRJtPVIxrhpbvVenFKbmz5vr4PUpZHzRmlAJiTtZXKHtL_vh8EDXoAsVR.UWp1 vGDdLmZ3GD6x0c5R2dxV5aAE0TyzOlnkPSi.R6QgSTjHtQKH9T0ZhWvWn4x0U7Zr9Lc_c9Jc1HhO L4UJjJIk0VXah8tilNPyo_ly7DG8mRHArk1vPk.miS8_SCNdL4C9Ir4FOTdgbCCgYDSiVHRm3JZa 254DhqTTNJAk552918DC7rYcbilVt1GjRdtgTQU0n_r3DQ6yMSw2ELzuhMYp1iU6Dqox5tWViJLL S_OIA5INUnVjOvFztIVwcLgib9vomJfBsuqw6fr_IZDg7Z_W0FhWMcWeBR69yJKIp9LEpTqttwAZ GVa0D5k05BSFnqh99VDzutY54LIFvSp7tIJJV4RgINYC1p6cEmfb0VG0oGlC3qow3KYbF5fUrs35 F_sWay_D6nkONDHMsXqXg_WTNRwX53mU3Gj89lxcQUU5p79IZ4SiBRDu2.ZzfqmH8kPAn7KjiEuA D1jvCFOkdij8NZOSKiwGcycH4wFc5hdQ- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ne1.yahoo.com with HTTP; Thu, 27 Jan 2022 16:51:51 +0000 Received: by kubenode544.mail-prod1.omega.gq1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 7bc05defc074a31e48e050f8eb7ef791; Thu, 27 Jan 2022 16:51:46 +0000 (UTC) Message-ID: Date: Thu, 27 Jan 2022 08:51:44 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: [PATCH v2] LSM: general protection fault in legacy_parse_param Content-Language: en-US To: Paul Moore Cc: Christian Brauner , Christian Brauner , James Morris , Linux Security Module list , LKML , syzbot , David Howells , linux-fsdevel , selinux@vger.kernel.org, Casey Schaufler References: <018a9bb4-accb-c19a-5b0a-fde22f4bc822.ref@schaufler-ca.com> <018a9bb4-accb-c19a-5b0a-fde22f4bc822@schaufler-ca.com> <20211012103243.xumzerhvhklqrovj@wittgenstein> From: Casey Schaufler In-Reply-To: X-Mailer: WebService/1.1.19615 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The usual LSM hook "bail on fail" scheme doesn't work for cases where a security module may return an error code indicating that it does not recognize an input. In this particular case Smack sees a mount option that it recognizes, and returns 0. A call to a BPF hook follows, which returns -ENOPARAM, which confuses the caller because Smack has processed its data. The SELinux hook incorrectly returns 1 on success. There was a time when this was correct, however the current expectation is that it return 0 on success. This is repaired. Reported-by: syzbot+d1e3b1d92d25abf97943@syzkaller.appspotmail.com Signed-off-by: Casey Schaufler Acked-by: James Morris Acked-by: Christian Brauner --- security/security.c | 17 +++++++++++++++-- security/selinux/hooks.c | 5 ++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/security/security.c b/security/security.c index 3d4eb474f35b..e649c8691be2 100644 --- a/security/security.c +++ b/security/security.c @@ -884,9 +884,22 @@ int security_fs_context_dup(struct fs_context *fc, struct fs_context *src_fc) return call_int_hook(fs_context_dup, 0, fc, src_fc); } -int security_fs_context_parse_param(struct fs_context *fc, struct fs_parameter *param) +int security_fs_context_parse_param(struct fs_context *fc, + struct fs_parameter *param) { - return call_int_hook(fs_context_parse_param, -ENOPARAM, fc, param); + struct security_hook_list *hp; + int trc; + int rc = -ENOPARAM; + + hlist_for_each_entry(hp, &security_hook_heads.fs_context_parse_param, + list) { + trc = hp->hook.fs_context_parse_param(fc, param); + if (trc == 0) + rc = 0; + else if (trc != -ENOPARAM) + return trc; + } + return rc; } int security_sb_alloc(struct super_block *sb) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 5b6895e4fc29..371f67a37f9a 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -2860,10 +2860,9 @@ static int selinux_fs_context_parse_param(struct fs_context *fc, return opt; rc = selinux_add_opt(opt, param->string, &fc->security); - if (!rc) { + if (!rc) param->string = NULL; - rc = 1; - } + return rc; }