From patchwork Thu Jan 16 23:40:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Andreev X-Patchwork-Id: 13942748 Received: from mx.swemel.ru (mx.swemel.ru [95.143.211.150]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B30D25A627 for ; Thu, 16 Jan 2025 23:50:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.143.211.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737071421; cv=none; b=d9X5qpiLxSvJZG4SphRCpZEIsWCFYiAzxa2+uU2eRi0vRAagB+98zAT/F6OYWZ+KBXkvi9sDloAkgp6yVqUa9nB9Ce9cKNh3uikBY4RhHFQ5/yXgkyofhdn2YxacsdECEetOT4d5SpyKKwzb3nAiTuVB7Z50ZiomCgzWPA7Umhg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737071421; c=relaxed/simple; bh=hNrv0hCr8yjDh83tC20QzcG/CIlBatkxaXHq+vF5fZA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KV6HL/iUawmWrg6CKO4bQZXWtXI2Bgfio5T+Uy7alW/sbvmQlZlK9y7vVylAAZxgQZlXsPdAbraucBLi5WGvoXR3a9s8TdvOyQ9aUBXdzWIyJZRraUnlIlrRc0b2Bdq0R4RqfLAsaY7kW/DdK5dM3QltfhwFMA0qRs6nRi3Wgs0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=swemel.ru; spf=pass smtp.mailfrom=swemel.ru; dkim=pass (1024-bit key) header.d=swemel.ru header.i=@swemel.ru header.b=L9ZUTXWd; arc=none smtp.client-ip=95.143.211.150 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=swemel.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=swemel.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=swemel.ru header.i=@swemel.ru header.b="L9ZUTXWd" From: Konstantin Andreev DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=swemel.ru; s=mail; t=1737070876; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pb/MNHvhvFXBbhTWO7zGURzWNjB4hwzKQfEEZrk0CrU=; b=L9ZUTXWdbB5GYVuJzAINkOW4o/FMSL4EDz6ike1lrooxKYYjUKND3yOGkDYMsPV3Ikimgu E9ysC/O+84SUwY1et8LK+HnsbVk2xgOiWYldo8AGfv9VQxeHbwuLzrA3aJjcn9C/U3iKR8 2G7N/UqyYgDpic27+7cXQLPTsT7splg= To: Casey Schaufler Cc: linux-security-module@vger.kernel.org Subject: [PATCH 1/2] smack: Revert "smackfs: Added check catlen" Date: Fri, 17 Jan 2025 02:40:33 +0300 Message-ID: <20250116234043.2904723-2-andreev@swemel.ru> In-Reply-To: <20250116234043.2904723-1-andreev@swemel.ru> References: <20250116234043.2904723-1-andreev@swemel.ru> Precedence: bulk X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This reverts commit ccfd889acb06eab10b98deb4b5eef0ec74157ea0 The indicated commit * does not describe the problem that change tries to solve * has programming issues * introduces a bug: forever clears NETLBL_SECATTR_MLS_CAT in (struct smack_known *)skp->smk_netlabel.flags Reverting the commit to reapproach original problem Signed-off-by: Konstantin Andreev --- security/smack/smackfs.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c index 357188f764ce..ef34b0bac603 100644 --- a/security/smack/smackfs.c +++ b/security/smack/smackfs.c @@ -812,7 +812,7 @@ static int smk_open_cipso(struct inode *inode, struct file *file) static ssize_t smk_set_cipso(struct file *file, const char __user *buf, size_t count, loff_t *ppos, int format) { - struct netlbl_lsm_catmap *old_cat, *new_cat = NULL; + struct netlbl_lsm_catmap *old_cat; struct smack_known *skp; struct netlbl_lsm_secattr ncats; char mapcatset[SMK_CIPSOLEN]; @@ -899,19 +899,8 @@ static ssize_t smk_set_cipso(struct file *file, const char __user *buf, smack_catset_bit(cat, mapcatset); } - ncats.flags = 0; - if (catlen == 0) { - ncats.attr.mls.cat = NULL; - ncats.attr.mls.lvl = maplevel; - new_cat = netlbl_catmap_alloc(GFP_ATOMIC); - if (new_cat) - new_cat->next = ncats.attr.mls.cat; - ncats.attr.mls.cat = new_cat; - skp->smk_netlabel.flags &= ~(1U << 3); - rc = 0; - } else { - rc = smk_netlbl_mls(maplevel, mapcatset, &ncats, SMK_CIPSOLEN); - } + + rc = smk_netlbl_mls(maplevel, mapcatset, &ncats, SMK_CIPSOLEN); if (rc >= 0) { old_cat = skp->smk_netlabel.attr.mls.cat; rcu_assign_pointer(skp->smk_netlabel.attr.mls.cat, ncats.attr.mls.cat); From patchwork Thu Jan 16 23:40:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Andreev X-Patchwork-Id: 13942749 Received: from mx.swemel.ru (mx.swemel.ru [95.143.211.150]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E7DC25A636 for ; Thu, 16 Jan 2025 23:50:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.143.211.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737071422; cv=none; b=NulJBgWJ2TI+8B+OCPvjZFQh4ChyMoNs+GRpqnbKVjXwq7U7skVGHNzl7dwtHYPHREYYtj+zZS0Hf8ILuBNNIZrhfIBE+pFNg/0RysybQg8JZ6YQkInyI0Sweu+qqk1BmayoSQyEBSQgCbpmxKcTSxwCcIRLXIF6+EoQ9G8WyA0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737071422; c=relaxed/simple; bh=IquMzvji7KAjfDVVSv2PMbd9ni3k0zAcByi67XngDfQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UJOvbKPXPKdPCXDqsp7+9haj7v92koUkmzN1nsnhI5vM80d1ynsCFDzIMdBFyxJUuG6dhZuShCTYNOOmypGdh6jNS6nzGjuOOke5dYQkYwwzO/D6arQI4cSJ2SbgPvErOtR3FidfDmAM5yrx88XstJZenfGHUIr37Hwe4GFkcCc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=swemel.ru; spf=pass smtp.mailfrom=swemel.ru; dkim=pass (1024-bit key) header.d=swemel.ru header.i=@swemel.ru header.b=f//MEvSR; arc=none smtp.client-ip=95.143.211.150 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=swemel.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=swemel.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=swemel.ru header.i=@swemel.ru header.b="f//MEvSR" From: Konstantin Andreev DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=swemel.ru; s=mail; t=1737070876; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Nqaniw4IbZuMCVqGwLu3YFwoHBUpaaswZcsdR1kuCuw=; b=f//MEvSR9xzrbnCKpQkK8hdjbYL3WbvDafmx66qQ0ySnXHuDjdC2ffqAk0VJf4Y9qxC4QS OTXO/0TJfcgxFAul9Dg8YPk3qlTg77a1/ags3Qeq0dzsKloI55lEw/W1h5Jg5g3uplEP2h VP1AdREssIzjCebp1Ybi6TTK8gkEvPA= To: Casey Schaufler Cc: linux-security-module@vger.kernel.org Subject: [PATCH 2/2] smack: recognize ipv4 CIPSO w/o categories Date: Fri, 17 Jan 2025 02:40:34 +0300 Message-ID: <20250116234043.2904723-3-andreev@swemel.ru> In-Reply-To: <20250116234043.2904723-1-andreev@swemel.ru> References: <20250116234043.2904723-1-andreev@swemel.ru> Precedence: bulk X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If SMACK label has CIPSO representation w/o categories, e.g.: | # cat /smack/cipso2 | foo 10 | @ 250/2 | ... then SMACK does not recognize such CIPSO in input ipv4 packets and substitues '*' label instead. Audit records may look like | lsm=SMACK fn=smack_socket_sock_rcv_skb action=denied | subject="*" object="_" requested=w pid=0 comm="swapper/1" ... This happens in two steps: 1) security/smack/smackfs.c`smk_set_cipso does not clear NETLBL_SECATTR_MLS_CAT from (struct smack_known *)skp->smk_netlabel.flags on assigning CIPSO w/o categories: | rcu_assign_pointer(skp->smk_netlabel.attr.mls.cat, ncats.attr.mls.cat); | skp->smk_netlabel.attr.mls.lvl = ncats.attr.mls.lvl; 2) security/smack/smack_lsm.c`smack_from_secattr can not match skp->smk_netlabel with input packet's struct netlbl_lsm_secattr *sap because sap->flags have not NETLBL_SECATTR_MLS_CAT (what is correct) but skp->smk_netlabel.flags have (what is incorrect): | if ((sap->flags & NETLBL_SECATTR_MLS_CAT) == 0) { | if ((skp->smk_netlabel.flags & | NETLBL_SECATTR_MLS_CAT) == 0) | found = 1; | break; | } This commit sets/clears NETLBL_SECATTR_MLS_CAT in skp->smk_netlabel.flags according to the presense of CIPSO categories. The update of smk_netlabel is not atomic, so input packets processing still may be incorrect during short time while update proceeds. Signed-off-by: Konstantin Andreev --- security/smack/smackfs.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c index ef34b0bac603..a7886cfc9dc3 100644 --- a/security/smack/smackfs.c +++ b/security/smack/smackfs.c @@ -904,6 +904,10 @@ static ssize_t smk_set_cipso(struct file *file, const char __user *buf, if (rc >= 0) { old_cat = skp->smk_netlabel.attr.mls.cat; rcu_assign_pointer(skp->smk_netlabel.attr.mls.cat, ncats.attr.mls.cat); + if (ncats.attr.mls.cat) + skp->smk_netlabel.flags |= NETLBL_SECATTR_MLS_CAT; + else + skp->smk_netlabel.flags &= ~(u32)NETLBL_SECATTR_MLS_CAT; skp->smk_netlabel.attr.mls.lvl = ncats.attr.mls.lvl; synchronize_rcu(); netlbl_catmap_free(old_cat);