Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2319313pxb; Mon, 20 Sep 2021 18:42:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFee3p9+enl8eP+OYKW3eXj0R++Hsf0d0PKy7tteE590CIT978WaIT54/g0iDMUDgBsONG X-Received: by 2002:a05:6638:2588:: with SMTP id s8mr21706263jat.43.1632188541024; Mon, 20 Sep 2021 18:42:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632188541; cv=none; d=google.com; s=arc-20160816; b=BxfbcnR7lGTRx3w9Gku7kXdcBvL2M104DqaOhGagbKdBFhk3ku0aJQFV6NbhprHwCj t2D9b5BNvhmFeTHHKukdWoRYju602FJ51azkCsLbb4a931MA0Jlvz6+b4KyOBskbqxAa ipfpj6dkCiLLp3rUYkyRLL0+QuL+lpYrliDyPRpoxo9ssFWqTILBCjTTXtSQfh88r91M cQp4wdSXQRwDwFpPSbaX6WNZJM1zt9X8CzE9t+yLmaitbER8UfWRZ8IoDRv2/4SZ/IuA 68vUq02YT9EPo654TA2bcEjF89lZIceHcgnSkqKxVYmY65GA8Q7fgfSK+2lsXwKKGrjQ gziA== 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=Txo3QvvU05CyHx3ij83DVpaUklUosQP8qRUIfLus0kY=; b=orteXDmFs6IuKEP3tmXtRrLxdbzQ/5wwWA64rlas9lRag+MldOt+w4rX69I08tC8g/ /GVTUIz+j/HKBu49akP9I6o+o3c+Z9WUI1g9l9j8WJdbu030imUU5fqM5uiB0V51TeDx xdUvZfRYlnAz2cOUHvfQQoN4B7jHuGR7WtD+SYb+yxeSO2gAF3+wzm8fsGntqcDPHdbG Ggw7L527nmYMbzCHgOolci73MzMU7t0nnN/FXhxs+y+5RE5f19lbBQhY0guIt41e3ggS QzRniFNSefq2stuC7lmmNITS10OnOobDnJvQc6QbKrQXFbotqjkx6mJJZA4XmsMODWaq wUUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qMOkNv6W; 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 p16si15348342iov.22.2021.09.20.18.42.09; Mon, 20 Sep 2021 18:42:21 -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=qMOkNv6W; 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 S229898AbhITQxX (ORCPT + 99 others); Mon, 20 Sep 2021 12:53:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:39212 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244361AbhITQuJ (ORCPT ); Mon, 20 Sep 2021 12:50:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5446761284; Mon, 20 Sep 2021 16:48:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632156521; bh=7wZnqVtzCaieeirAr59OTc2qWcSAp87QUfatIxHr23g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qMOkNv6WDwS+tWxMawBH8OstokqekHkgrQBNj2ei9Fy1DCYRNFhFWDBO2g65/7adR JaKstmTW/ot0OZiikHWtXzGCJHnCTmd6Xl9KPRdx/VhKQFU+CDUIrdxbP5wF38KRyH lQesdDKobeBXQdYSbgKys7IKEdJ8s+e+qn4rVLz4= 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 4.4 090/133] Smack: Fix wrong semantics in smk_access_entry() Date: Mon, 20 Sep 2021 18:42:48 +0200 Message-Id: <20210920163915.589327941@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163912.603434365@linuxfoundation.org> References: <20210920163912.603434365@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 0df316c62005..84f38b694242 100644 --- a/security/smack/smack_access.c +++ b/security/smack/smack_access.c @@ -90,23 +90,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