Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1006367pxb; Wed, 6 Apr 2022 06:33:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxH1/eoE/avx0YKXi9RxwBhQW/1r6Oqldf89L2PpM3NE0dWzaSe0NX5TB1q6xnuD515iuuN X-Received: by 2002:a17:90a:306:b0:1c6:ff30:70da with SMTP id 6-20020a17090a030600b001c6ff3070damr9777526pje.117.1649252008985; Wed, 06 Apr 2022 06:33:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649252008; cv=none; d=google.com; s=arc-20160816; b=smlGDJb2jUYxsVNt6iReL1QPsgGPpTG7yJrz7YoYOlIej+yGMHZeyCf7t7qmWv2wPN 6lZ1T8YlsBUdfzNHVV+HMa/ZBZZqB1pNXrP5hYPC3QpyaiJPMEbuZGLo2oClA6FJhFc2 BWQ7UdvB9VRhyWTNlueKY7rb5vIe/0iNcQ32eGqJp/5di0mnY6HauwuX8rHzbGVaIXmu kYAaAAeOVELO9+B69O1P2z8jxdR/uD0EHJVA5TIY+k+CSFbTYmihnvN4nIykER938VrH Uf0Uxn1mKWbZ0LhG3yaeVUHv79+T8JMQkhGpt/0bWQ9hbing0kul4AK6pL9oybJl1Lwd 5ulw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=W0MNbW9jSiyDD+vM/qnNHdSnPHCi+Ec4qjcyW6vKBuE=; b=FL3WhRAVWbm1ihd+SL6l72CtuitE1eF+YzOKv3sjdLjNYt1nyhVEtShy/2VWk02lvR jpZlY/oZVscfRRwJm+K6FksguSwn7/j+2sSIDs6qRiLfa3bTpbmPpB3VPca0ZBTh+3LA oM3mjPvL+quWws+XYqkI9+23rByfLVdw0ja4JUOgXsRP807dSQx9eK6Q4WfLhHkOOXwT f2WIHNXa3+gabDXQ75IYIPFh1mfNm2CygiFP4TF1eIuwR26GQ/0L/X9N3/FyWOo0Z9Qf zcaUkQOHUR9R9np98gDaQjq1IafPOYg/hpnWV5CWrcWuDXJJtt7U3Glx9WtfcxibxPcQ 3EXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qgbuDT+i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id c19-20020a056a000ad300b004fa831f601csi17424711pfl.231.2022.04.06.06.33.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 06:33:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qgbuDT+i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DF2B54DC5B0; Wed, 6 Apr 2022 04:12:51 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442528AbiDEUHV (ORCPT + 99 others); Tue, 5 Apr 2022 16:07:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349809AbiDEJvg (ORCPT ); Tue, 5 Apr 2022 05:51:36 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3BCC1FCD2; Tue, 5 Apr 2022 02:49:37 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 85005B81B14; Tue, 5 Apr 2022 09:49:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7576C385A1; Tue, 5 Apr 2022 09:49:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649152175; bh=02vN4Sxu3Mspd3SCD/KExVELM6QtsTgtq7JitGYxUVE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qgbuDT+i39whwRO6a4SJLh3AbdDHtwCl9KVRtVzjm+UvLxghLGyr/rkNd01iNqti9 LA1mXYFm0JeK8Oetc8xPHuOY/TY9wft/Z3c8kBsI9KFtV6rG3MsLpcgKkHEQhokbyI V8wD4bduJ0mPryD9ixSwgGQ4S671MOaWX3aB5QYY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+d1e3b1d92d25abf97943@syzkaller.appspotmail.com, Casey Schaufler , James Morris , Paul Moore , Sasha Levin Subject: [PATCH 5.15 682/913] LSM: general protection fault in legacy_parse_param Date: Tue, 5 Apr 2022 09:29:04 +0200 Message-Id: <20220405070400.278041421@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Casey Schaufler [ Upstream commit ecff30575b5ad0eda149aadad247b7f75411fd47 ] 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 Signed-off-by: Paul Moore Signed-off-by: Sasha Levin --- 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 67264cb08fb3..da631339e969 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 f3c8acf45ed9..9a89e456d378 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -2915,10 +2915,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; } -- 2.34.1