Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp446312pxb; Thu, 9 Sep 2021 04:47:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyT+fh6y3yZj6MtFt/JL3ahKmRdz85I9eK9WzqVM7dmzY/ZcMAWnbjlFZ6FZwWqWyCT3PkB X-Received: by 2002:a17:906:16d1:: with SMTP id t17mr3001879ejd.360.1631188049478; Thu, 09 Sep 2021 04:47:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631188049; cv=none; d=google.com; s=arc-20160816; b=PuL2sFhmzddnrzn3f3qWnaRSlvhG4IK73oxcM4HZ4hI4drktHjn7groeASF4YKCOKK lbzF0F2pnxmoxNRZup+jIU7/tV9Bk38NeHs0FxUxDeRlJtIEEyco7bQFOyC4Wuj6OHHK CewuVzvImLvztox0Hn86Zb/oomfGXdD0fOEazYZotHZ535EYsCkJHXywzVskPob/Kd4j cFZSJ3Lkp//PCtNyU2niyQS324+aGxTOmjq4N/yMD7ZoCrXm2Zc4Rm3Cwcu8pOUoG4yQ 39jz3VKMAtXY2n8/GrggPCDNrusv77gmnqpsbI7GLTACw8lAbKlVrtbX+dyPvQyP3ktL 9LNg== 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=jjHdvRbYteHMVL0Rn87eWz5iPxs7iEgDHkY9/DrGHwA=; b=F+jsNFFhH4XWXOp5LIESAW9muDOtQQa3PlLfp7pWJ1KmYnKii9khUUEkoa2va4Zt3G ygJsmbtvl5nh9DbKsLbp2UebGzs0C9dZ1F0YQs0N1/e/+neYN1OiUwdAjfN51uEEDGai QsrplbjzFNO56qXkEE7Lm6peqCKZRldr8VDHb3jKrAUi7XoQg8TluOMVFETzGrymg5zX Gz4IpBPaikKO0F4qe+fe2ZlL0aSP/qmSBBoWjLSPeLXoUTYLoMcm3R9kgZmtm3cI77fg kUMb5Wul6ZmdDAHRSKm55sAyBDfHdWyRkT7AqFw35tKgOJgy2dxgpONuQSZYURXoP2y0 CRvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=J7knhClC; 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 h4si2080496edt.426.2021.09.09.04.47.05; Thu, 09 Sep 2021 04:47:29 -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=J7knhClC; 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 S235594AbhIILol (ORCPT + 99 others); Thu, 9 Sep 2021 07:44:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:46150 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237343AbhIILm6 (ORCPT ); Thu, 9 Sep 2021 07:42:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D945661212; Thu, 9 Sep 2021 11:41:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631187709; bh=KUOWcRDTPFwGpcqxKYX2cUxkMEjRKTcIlgr0tuZt45w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J7knhClC/st7+CPFrB4H5BjHuFrsNR/00vJyXYQbk8hNyYcK4CxWOPkzFsDGv9yDK N8RjoiP4HsSCmMCaroWjAiJPm79DR7TSozWt+OoGBsYmyL/AtM+XoZKLSolVbhkBMP r2kLK1rfgS6fE3R9HH+g6gm3Rn44j+qvBYgiy06bWo/70rUxtG2Wfr614ME86mXcit bqxrcsHYWwsRxou1y0KQZL5Uuw6vSzSZLckEH6Ob/cTZAkox4mtwP7yZFSp0Gc7c9S 6sWinfmDB5VPqmshqHrwqzuRA+ZifqiL1wG4g17nHkcrqk96phZdmZf3beLQAfHO8b G9xz2eQGxypFw== 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 5.14 033/252] Smack: Fix wrong semantics in smk_access_entry() Date: Thu, 9 Sep 2021 07:37:27 -0400 Message-Id: <20210909114106.141462-33-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210909114106.141462-1-sashal@kernel.org> References: <20210909114106.141462-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 1f391f6a3d47..d2186e2757be 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