Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp517365pxb; Thu, 9 Sep 2021 06:17:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyyqPL+dhy6q1Vrf1wzfcaBpenX7gDhr/nuS62BGaGxGHXqRu+bgQOCIjC6hlGCj4Jq+E7M X-Received: by 2002:a92:d848:: with SMTP id h8mr2233803ilq.230.1631193430532; Thu, 09 Sep 2021 06:17:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631193430; cv=none; d=google.com; s=arc-20160816; b=nQyRkkB+OYp/jOk5gcDc4G7ij7I1eAwIx5tjxCNEHmNite3EBOFZMxGPLUPH+QqR0e s6Q9SCSjj07R/ZcPN9XUBXqaxhzP3Nxltf7euZ5lGgkW9jy1Qh6+aim1LheX+RK8xZh5 CXAZeBsYkF4Z65kZjrOUobLHkG8EHIl3vUkqUL33V7WsbqE99Npfa8Guo9nblDAzZ2NO Z5Sy/OjgdGVaQ6R6BtshHbAIrhMp/I2GcAVNhL5rq0uXPhv7XKMcSJ06T4OOq3p6CvXQ NFyuEi4okCMfLRmVeca53MFAHXxQ7bClqbpmi20Z24aGlP3QwLWDdKG9zfUWCYQskyg/ y+mA== 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 :dkim-signature; bh=3kleFsBGo+Xoz4SMrBTsIq6Odv5RQlDONFWhpY7pKmY=; b=JYw4PzHKCgnzL8RvmUkJtFM9PrqCEteyUCzXH+5lAWTWPjCmio8zKxRK2nNSLRLfRH FB1x+Wtq0e9udXQ766QiAjSLbsey12y+1LmA/fcVi44+TkCsHWdnXrGqvev/4mKu8eI9 Mt+wCZpT1loj0QpMuSryNgt9LgcdV3FbijGRq2NmdmsMcsu5FuPgHQOm6FQOZ8WDeD75 7fgMhkoSE3Y1W9xkcFP2+QNR33omgAme3udux2HfadrM3usJ6/kTWjyZIrkW262tpxFn yAPwdNibsNe6bPcPUn8wE6OAv7pul2BbZ6HFB/GqT85CdgVy2O0F48erJkcfV1ILnR2J ex9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cynUs5dW; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m16si1712274ilc.181.2021.09.09.06.16.55; Thu, 09 Sep 2021 06:17:10 -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=@kernel.org header.s=k20201202 header.b=cynUs5dW; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359329AbhIINQz (ORCPT + 99 others); Thu, 9 Sep 2021 09:16:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:42434 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243524AbhIINBD (ORCPT ); Thu, 9 Sep 2021 09:01:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 33195611CA; Thu, 9 Sep 2021 11:59:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631188750; bh=oif4ZMjsAOjF6vqMYvCMCrWy+KWpEqTe9imNIsHB/mM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cynUs5dWd6/sy6s1cHZ/Srk+YFsWkmNn6auwbieJZrHP4bkQYPYEMjFyTWsgj7F3Z mSCBAYnUeeBYnXesKpq/x41U0kVJj3pbYs78e7dvIXyP/sUldbzNyyunweBgRh1JwJ RXUePfBG70TIChO+6DS3I2R/bVZQObxK1DDZ+LR9tvduBgl/1q9KLinKOlKt0vTbMQ FnN6uj5Wg9p11sZ1nwut5bqcLriNw/vYf0d2NKRh+U4PVPoCzLh8q8iZ59QxAJarbU 7DpAvmUDxbcbb0ZrmgV5VNeFNnyHf9oUEMORBc2H7QpYxFOcZb2PHhyIVSeKyQC9iM E+GttodL+dKlQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Tianjia Zhang , Casey Schaufler , Sasha Levin , linux-security-module@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 08/59] Smack: Fix wrong semantics in smk_access_entry() Date: Thu, 9 Sep 2021 07:58:09 -0400 Message-Id: <20210909115900.149795-8-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210909115900.149795-1-sashal@kernel.org> References: <20210909115900.149795-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 a9c20821a726..c8e82d6a12b5 100644 --- a/security/smack/smack_access.c +++ b/security/smack/smack_access.c @@ -85,23 +85,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