Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1678617pxb; Thu, 16 Sep 2021 12:45:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMgS+YKj//WcqKHiy4JRR1DIEJDoyeKOXE459xPd/HvEk1KEXQV3io0k7e0H/tFQoDzWmt X-Received: by 2002:a92:8743:: with SMTP id d3mr5088738ilm.237.1631821544308; Thu, 16 Sep 2021 12:45:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631821544; cv=none; d=google.com; s=arc-20160816; b=Vvz7EAlEVn/0WsffzvhinFc0ee87VuDPT0Ax2EhObEeFosmLMCkvq6svfhjIQO+x3W Zb2yE0scp7MeF3TP1qWx4oLdJ0E/OZU31SBxz9dG4gbzB7nn0n5+SyWY/CZKje539wWE IjkhTTCJsy/2fmv2ILMNvU9jV4ROL1fwzhmI74bciJNswAGqmMrh7W03YpyypvJKv+H8 n/1GhDef9MD4F55sLbMz64u/7IZbFoduVH2ILz5tALWcJA7zBvlQZEnWCYEUhfJdf/JD PO+6/GzRZvXlcshWcH9/j/s1Y2+6yrX5hi53I9Cr8q8AKOK5fBv8RWGsYuKkLP1bKk26 86dw== 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=uu4ZAi6B07Mtkvm5Ygu+nWRsYYVLFjt+gj+C9vR0gYw=; b=oGoLLBMoH70XQ0M612wU3Pyv+Rgmb86EOr3DVRVr8UlVvrRAGVbcUPLATdqW25XWg9 FOQ75xyZqG8IXWftB1YcaGyno1WLYBJF3L/wwkYGeNT72BNhd/aRjeBDBYyrvVX52pQ7 uEG1Zh8Q3wmedfSV7npSteaDEULxEdHaHIVPheNgD7rUYYptVNS7wIEvN8cm+B3hOLmL fgU4bCIzgf4CmDM1iZ896PSLg3mdB2gGlPah0i1E3srttRcJbahEuI4jStrGuAhRUyfR 8MkRdZpNxhyCBGsTKN78VqhZXHi+0vCFPbREnB/Yn4k+r3Izt5w438RrOrAquxwaxRXj uFrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xMdfXIdK; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r1si3416120ilg.125.2021.09.16.12.45.05; Thu, 16 Sep 2021 12:45:44 -0700 (PDT) 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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xMdfXIdK; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230152AbhIPQUK (ORCPT + 99 others); Thu, 16 Sep 2021 12:20:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:46774 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233745AbhIPQL3 (ORCPT ); Thu, 16 Sep 2021 12:11:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2A34D61353; Thu, 16 Sep 2021 16:08:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631808533; bh=6mcHWBWcWXuC5Tmts2xdto8ZuoMFECF0/tuKk/l87Uw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xMdfXIdKj64pvWZvy4wNmzdTqW2xxgszSnVrWUe3V6V9qnGPFWC6Gad+PcLd5y0vb FPsmx2ICeMwXQCUnMkevCCg1Fvp1r+k8W45sVsrrHSIo2mE7gK+Co826O6VKcrCWk2 RiOe8UHtJB3nZdISfsrgpStfIGwqengp+/vZFg7g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tianjia Zhang , Casey Schaufler , Sasha Levin Subject: [PATCH 5.10 126/306] Smack: Fix wrong semantics in smk_access_entry() Date: Thu, 16 Sep 2021 17:57:51 +0200 Message-Id: <20210916155758.365223084@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155753.903069397@linuxfoundation.org> References: <20210916155753.903069397@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Tianjia Zhang [ Upstream commit 6d14f5c7028eea70760df284057fe198ce7778dd ] In the smk_access_entry() function, if no matching rule is found in the rust_list, a negative error code will be used to perform bit operations with the MAY_ enumeration value. This is semantically wrong. This patch fixes this issue. Signed-off-by: Tianjia Zhang Signed-off-by: Casey Schaufler Signed-off-by: Sasha Levin --- security/smack/smack_access.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/security/smack/smack_access.c b/security/smack/smack_access.c index 7eabb448acab..169929c6c4eb 100644 --- a/security/smack/smack_access.c +++ b/security/smack/smack_access.c @@ -81,23 +81,22 @@ int log_policy = SMACK_AUDIT_DENIED; int smk_access_entry(char *subject_label, char *object_label, struct list_head *rule_list) { - int may = -ENOENT; struct smack_rule *srp; list_for_each_entry_rcu(srp, rule_list, list) { if (srp->smk_object->smk_known == object_label && srp->smk_subject->smk_known == subject_label) { - may = srp->smk_access; - break; + int may = srp->smk_access; + /* + * MAY_WRITE implies MAY_LOCK. + */ + if ((may & MAY_WRITE) == MAY_WRITE) + may |= MAY_LOCK; + return may; } } - /* - * MAY_WRITE implies MAY_LOCK. - */ - if ((may & MAY_WRITE) == MAY_WRITE) - may |= MAY_LOCK; - return may; + return -ENOENT; } /** -- 2.30.2