Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp722601pxb; Tue, 5 Apr 2022 20:21:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLPw8gg0dxe5icWWuUzaZM5o9XFtQtgE9kUvgweYW3MVIfUVEj6Gb1stZ8IKPJm8JJmx6g X-Received: by 2002:a63:3718:0:b0:398:1086:e8ec with SMTP id e24-20020a633718000000b003981086e8ecmr5532894pga.498.1649215298827; Tue, 05 Apr 2022 20:21:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649215298; cv=none; d=google.com; s=arc-20160816; b=cflbW6m/zrK/tq44QRuFOcWb4ZLu4rykN3lz1cG89VkmIcdxVU0REtUFsiDjPKkUzq Wvyb65eQVqqyY+ugLvpEhuwTmRnTLM19aRiBzUE16+DrSeFCmVAvigB8UbWZqHPmaRJJ tBupJzn8OrC3075VcUy8woKVHESNSLJC0ZkdW6Fvyb1hg5EVfNPWvmo7gGq/mdYsg7De eRdWPycZQHOWfd4b74CNdWbOiCeorWYCPzHi8mDuspHLLPVD76EtPWXlBCvDTHxcLsGn ycxQMCvi8uZfAgNvKBwGuG03E+qQ9lEmrrN7szW1ful86059ErSMSI99Q1bPXCV1d6Rq 3fNQ== 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=wXtbEw8Xsk3tg1FVxb6txZW22ephq3jLNZLAS2Yvgfc=; b=RW1c5j8pGIoJGCbF35wZ9AY2Pb4i4LU55suFnVxyHI7GDswebVQlhLlbsoEvlfeJ4l MK8WuHY5OvEIzOlSqYwZoI6GjvqytwmjPULUhXbUFOmfoOyQFbx/lpMo1Ml9tlC3cz5w d2K6DamQdJD2f/1ds0I0Y5/dDiZmE/4pRkAgavXYOAqmgL8YAhyt3J99TfmKY4G591Ug LFkGXME8xPrEeEhwLY9Lp+gC2gllCZBXUr2JyyByCAy4c7GhEqp6HwU17BBlIYPUl1PM KJ6ONqShaaBtY+dlnVHy9LsMlynR+zkON9/bpZjRXANIf9uoCsiBYp6XWUf3lp1zF8gc ZgBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=adNZPA11; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id e13-20020a65478d000000b003816043efefsi1647270pgs.484.2022.04.05.20.21.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 20:21:38 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=adNZPA11; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 9F61D30CB99; Tue, 5 Apr 2022 19:55:40 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1388077AbiDENUv (ORCPT + 99 others); Tue, 5 Apr 2022 09:20:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344361AbiDEJTe (ORCPT ); Tue, 5 Apr 2022 05:19:34 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3C8011F; Tue, 5 Apr 2022 02:07:56 -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 9EE72B81A12; Tue, 5 Apr 2022 09:07:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E940DC385A1; Tue, 5 Apr 2022 09:07:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649149674; bh=qBElXJ90QRgQ8W5VnsNr6T5Wz+r+3jv9YBNbGL+C/PI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=adNZPA11YHOGWheHySjb7gIBxAO6jT+V8e0kM+DE/1sglWxZTV+bK/udLK4zsLEov U/8EZhtG2D/sDILHttpMvWYxFOzsQDwn/lI9mCYSlR4nn+09tHTCO3RkrKFSRcKC35 5XN//MB8YDq9seyGXBeymjUke55v1bN9za1uMzeg= 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.16 0751/1017] LSM: general protection fault in legacy_parse_param Date: Tue, 5 Apr 2022 09:27:44 +0200 Message-Id: <20220405070416.552864745@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@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 cf6615b5e820..745a8bf66d91 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 93eac9464c5f..69b0709bd156 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -2916,10 +2916,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