Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3566392pxp; Tue, 8 Mar 2022 17:37:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJw4fJK70bZXsHHK+ZVKsGlkUnHqK060hMvja15WpV45bFgWtgTPQxhuZVmBIQ9irropY/77 X-Received: by 2002:a17:90a:8987:b0:1be:dde1:c672 with SMTP id v7-20020a17090a898700b001bedde1c672mr7853371pjn.208.1646789856752; Tue, 08 Mar 2022 17:37:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646789856; cv=none; d=google.com; s=arc-20160816; b=sK72mmYiFsDBAt2VlUWXICe+xTD+NbfyivI8bmtI40lvjS3Ks2milIMD7ZCzj7oWte jdY81MizPiJ+LKsks2lpfBvC4rdfYW4jDFd5VOENYlqvA8YxVECO7sApW8J0UZ94Wl41 pUDFt+9bX6mWlfRZea7kD/oayhuui+kRyHs+/YY2enLJMCMJVZtrIdN7TbtEu+HPy0Zk ZqQ/kixkYLpnv2l465nudB1HzcBKzxQpyrFFbJ+MSCaHzFyEGmlzwkdfzzS6UfbbwhbP 0I6gGPfoe+zm4A5fWGQo1Zka1z25WsZPpu/3nche7CXOQi50y0Wth+e4IdRC/qzAKjvv kMOQ== 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=DOdGQeqCpYXaPiv3FTiB/YOqJ4lEo750BpQvbc/UAeI=; b=JqdBMOsdLDaxarnShMB8v7IbUv8O0BzzaC9baKU/1MJMIJ79fWAtAc+f2UkutqT9P/ 8t+A23EdF/89RmKxA+8Bihr2Ex7s/xmXVZ/jcccXOxW2wvsB8eMXFDPIIcSZaVeQhbXe COWSB+/bCikvvfzI/MTDMsAMKWoCGimvADt0AtGlk3zcB2l9pz7eke9yd2tUM7NDz876 fETV/0ufUZtBu3GjMQe+Exg89krOVAqVGXIXzjwtVo43miET6cu4suDXbEOXucUjiNQ4 qlaBlb0Kuchky9Z6aHb+AJQTg4uyYl0cEsDWCZ5ziaRoBCa4xLLs3LBsnDPLx5Pf1FSp ff+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@googlemail.com header.s=20210112 header.b=bMbwrDBc; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id bd8-20020a656e08000000b003737c6010edsi477646pgb.861.2022.03.08.17.37.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 17:37:36 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@googlemail.com header.s=20210112 header.b=bMbwrDBc; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DCF9B1FE03B; Tue, 8 Mar 2022 16:30:07 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245053AbiCHRKh (ORCPT + 99 others); Tue, 8 Mar 2022 12:10:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348421AbiCHRKe (ORCPT ); Tue, 8 Mar 2022 12:10:34 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1FFA36E1A; Tue, 8 Mar 2022 09:09:37 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id d10so40679852eje.10; Tue, 08 Mar 2022 09:09:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DOdGQeqCpYXaPiv3FTiB/YOqJ4lEo750BpQvbc/UAeI=; b=bMbwrDBcaXwa367L6NIq1Dx+ubrnoNm0OZbFllsIFAivPdFLc923Lvjdhdg9Mz7m0P vZt2s7jx/4SdeOXuZ53+J/AbTQ2aJuUIdSN+rpNTqdmr0R71la2saasNcju++Ll4SeEz 7Dzb1wxygwgg7tA1J2GNjyfrj//kkM4AleeFoPI8R/fk/SvpFYxUapLyHicPewphSMoi 5mQ1/F/dHmklwz4rhozdYGlFDaD67Nn+35oyXwVq0HI7RMIG4s1X15blUfgGjsXFbXT9 0u83L2R4njw62ySrlwy7p2wNdkSYmyxmJu3HEvXW6n6A1BuuwpKcSm8RrfQGKAvi9NTy +ACw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DOdGQeqCpYXaPiv3FTiB/YOqJ4lEo750BpQvbc/UAeI=; b=U6Q1ZvXLLn/oTftzdgcd2zsWupBHD9M3aY7Y7lWL2jMXpR91yRHtMusZZPYeGOZDDB ph0+rh1kkB6T6KEPbDhWh0z5L8+aiWPSXmrnF5K9Gx40efs5IdEahwE4zSYs2dwCyy7d TkcoIJ68DBF07vf9Qt341CHnjqo4C4wBRU4OffnoJN4dgbzX8/LQmr3U7IsIcvcoNwOl NGcTZSjDikcQWP+lqYwNBMvPIMZXfcB2ZaGsy9sNhx3iNO2yVVMA4MAnGnVOC3EvWa9J 7hklsWaHQgFsmmT8vODYJ+WaEQbFKpY16lsPfCGpD6ez5/DfWpMJRWY0DwxH/yNSOTQq Qgjw== X-Gm-Message-State: AOAM531cJ+wyd1BIZmW5qZ35C+HFEKT+BqR29fdvgu1AgmeWePN8wMyE tX/J1NyDPWbagiJu6aQCRoDT9Sd+mn8Jwg== X-Received: by 2002:a17:906:2b97:b0:6cd:6d67:ab5d with SMTP id m23-20020a1709062b9700b006cd6d67ab5dmr14406385ejg.723.1646759375991; Tue, 08 Mar 2022 09:09:35 -0800 (PST) Received: from debianHome.localdomain (dynamic-077-006-252-105.77.6.pool.telefonica.de. [77.6.252.105]) by smtp.gmail.com with ESMTPSA id f6-20020a056402354600b004167d09f418sm443751edd.55.2022.03.08.09.09.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:09:35 -0800 (PST) From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= To: selinux@vger.kernel.org Cc: James Morris , "Serge E. Hallyn" , Paul Moore , Stephen Smalley , Eric Paris , Richard Guy Briggs , Ondrej Mosnacek , linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org Subject: [PATCH v2] selinux: log anon inode class name Date: Tue, 8 Mar 2022 18:09:26 +0100 Message-Id: <20220308170928.58040-1-cgzones@googlemail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220217143457.75229-1-cgzones@googlemail.com> References: <20220217143457.75229-1-cgzones@googlemail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Log the anonymous inode class name in the security hook inode_init_security_anon. This name is the key for name based type transitions on the anon_inode security class on creation. Example: type=AVC msg=audit(02/16/22 22:02:50.585:216) : avc: granted \ { create } for pid=2136 comm=mariadbd anonclass="[io_uring]" \ scontext=system_u:system_r:mysqld_t:s0 \ tcontext=system_u:system_r:mysqld_iouring_t:s0 tclass=anon_inode Add a new LSM audit data type holding the inode and the class name. Signed-off-by: Christian Göttsche --- v2: - drop dev= and name= output for anonymous inodes, and hence simplify the common_audit_data union member. - drop WARN_ON() on empty name passed to inode_init_security_anon hook --- include/linux/lsm_audit.h | 2 ++ security/lsm_audit.c | 4 ++++ security/selinux/hooks.c | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/linux/lsm_audit.h b/include/linux/lsm_audit.h index 17d02eda9538..97a8b21eb033 100644 --- a/include/linux/lsm_audit.h +++ b/include/linux/lsm_audit.h @@ -76,6 +76,7 @@ struct common_audit_data { #define LSM_AUDIT_DATA_IBENDPORT 14 #define LSM_AUDIT_DATA_LOCKDOWN 15 #define LSM_AUDIT_DATA_NOTIFICATION 16 +#define LSM_AUDIT_DATA_ANONINODE 17 union { struct path path; struct dentry *dentry; @@ -96,6 +97,7 @@ struct common_audit_data { struct lsm_ibpkey_audit *ibpkey; struct lsm_ibendport_audit *ibendport; int reason; + const char *anonclass; } u; /* this union contains LSM specific data */ union { diff --git a/security/lsm_audit.c b/security/lsm_audit.c index 1897cbf6fc69..981f6a4e4590 100644 --- a/security/lsm_audit.c +++ b/security/lsm_audit.c @@ -433,6 +433,10 @@ static void dump_common_audit_data(struct audit_buffer *ab, audit_log_format(ab, " lockdown_reason=\"%s\"", lockdown_reasons[a->u.reason]); break; + case LSM_AUDIT_DATA_ANONINODE: + audit_log_format(ab, " anonclass="); + audit_log_untrustedstring(ab, a->u.anonclass); + break; } /* switch (a->type) */ } diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index b12e14b2797b..49c0abfd2f6a 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -2965,8 +2965,8 @@ static int selinux_inode_init_security_anon(struct inode *inode, * allowed to actually create this type of anonymous inode. */ - ad.type = LSM_AUDIT_DATA_INODE; - ad.u.inode = inode; + ad.type = LSM_AUDIT_DATA_ANONINODE; + ad.u.anonclass = name ? (const char *)name->name : "?"; return avc_has_perm(&selinux_state, tsec->sid, -- 2.35.1