From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D22EAC7115C for ; Fri, 20 Jun 2025 15:02:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 646906B0096; Fri, 20 Jun 2025 11:02:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5F64C6B0098; Fri, 20 Jun 2025 11:02:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4BE516B0099; Fri, 20 Jun 2025 11:02:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id DF72F6B0096 for ; Fri, 20 Jun 2025 11:02:32 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A98AF1A0C92 for ; Fri, 20 Jun 2025 15:02:31 +0000 (UTC) X-FDA: 83576095302.11.647B0CC Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by imf22.hostedemail.com (Postfix) with ESMTP id DBAF7C0026 for ; Fri, 20 Jun 2025 15:02:23 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="PF9/tVGC"; spf=pass (imf22.hostedemail.com: domain of 3-3dVaAYKCIo6so1xqu22uzs.q20zw18B-00y9oqy.25u@flex--seanjc.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3-3dVaAYKCIo6so1xqu22uzs.q20zw18B-00y9oqy.25u@flex--seanjc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1750431744; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TIvatz/B0KFp5dEup/nosXT8XyxE4hqnW2qwmbJi7ww=; b=zsl++Uqor03czB/vBghIj19DZR1vBcznuvgZezOpvLyo5tgsgBNP4bOxn/F6RU7LwHqVzU ci6ibqCSoSbJhKnRWF5pxPlaU3Cyxs7QZGhqh9Rzw7xR44TYvb+viaMy328oY7YUbmFl25 pyGu+vCCjL5R+MC1loQmka/fZbeiGWg= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="PF9/tVGC"; spf=pass (imf22.hostedemail.com: domain of 3-3dVaAYKCIo6so1xqu22uzs.q20zw18B-00y9oqy.25u@flex--seanjc.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3-3dVaAYKCIo6so1xqu22uzs.q20zw18B-00y9oqy.25u@flex--seanjc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750431744; a=rsa-sha256; cv=none; b=UPcfdACyfkcUx1j6Ihkbf8gewR8rrRB9YOJRApebyLne04BzriIN9dPyoCIlYrOI8Bc1Ir RTgqY413yBdxNUoGOgBbir5spUB2kW3aDuYfhWGe5KJZEJz/0j1AuOzk/y687JRagVdJRQ oqQrhXcO18DstciCvrwetlmnj/Fc9yE= Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-23692793178so20431835ad.0 for ; Fri, 20 Jun 2025 08:02:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1750431740; x=1751036540; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=TIvatz/B0KFp5dEup/nosXT8XyxE4hqnW2qwmbJi7ww=; b=PF9/tVGC+HVRY71t+vqlMJ+Pq++DEgwGFTfF6kdMz6Cq7dycI1QAb60wCBTroBqD/n 6vHItrMXs0sgxyBnJvYYGblujOIWWaGN+BOcxwi1UJ/KP5o8sc+yw1+QrdH9Eq2/b9gt 387f2LqkN6EJKaFsjKUpxEj2G5FPUh1DLIjQxElGUPTGp2VcC4Gi0ZYGIuGkPMMNtSMV kSjnXxp+PkuWGP/aQ9wfAzDK7RATA+B6l9DhEwoN33u0k8DTvaHCjzcBimRqTEQEUSGm XipCCipqOyGResI6Lwx9ozr8ADeLJfcixvLEf7gV00xeISpFPU3Uef8zIXZx24rhxn7V 9R6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750431740; x=1751036540; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TIvatz/B0KFp5dEup/nosXT8XyxE4hqnW2qwmbJi7ww=; b=BSJZOUiJHoDMAnYXWq8pU9DmiB33Sf23VfZELGGdzzTy6BYB1s32wANq98XZPEVKKj gG0Rukga1FzmLIRua2+OgIgfqDnddN/ym19oqGugJc1o/aZnbps/18Vw9s2ObB8oo8bz s+yjNuf5bmNSQ+J8fu71s8X2JCZ7l8OsLGvq/SBv8J+zNNBIGP/2Q3oY9L2BDxmSNAds 76hfmdp3KzeuT17XW4B2TMiprc+Evs5nsoMGHx1s08FI7a8WFNeYhbwuko0YUpaiC+5/ r09KjMuQhrUCb2d69mnocBgd6r9EaJp7PXX7ne/aPXS8v/fJ0FuPZEH+NazrwtYEb2AO G5ag== X-Forwarded-Encrypted: i=1; AJvYcCULSsI4z04Y5E+nhFibyFJF/Jt81gou8SgJgk75WoFFkSAUNUGnpLK3cFaxrFdyBza2iPl7KzAzQA==@kvack.org X-Gm-Message-State: AOJu0YzWX9RYOh92v8Nmg8jGIe7OkQ/zsqtIZC3QWCpZmZTuuhwzZUtD YMb3uRgXw0kcXWPmG92PHQAlrI76Cemn4bwH14DQDOn8YnN0+GNNaZWN8MLbYQIKdxzM5MCUoG5 w8sNbTA== X-Google-Smtp-Source: AGHT+IExJJEDLfHbw/cDZIvMSnQtiL3FA6aoOj5uTpsDJb4W7kOrg449hrd2zU8N5OQvcBYHhv4AeU4UpNo= X-Received: from pjbta6.prod.google.com ([2002:a17:90b:4ec6:b0:312:e5dd:9248]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1c09:b0:311:e8cc:4256 with SMTP id 98e67ed59e1d1-3159d8cf694mr4153837a91.22.1750431739886; Fri, 20 Jun 2025 08:02:19 -0700 (PDT) Date: Fri, 20 Jun 2025 08:02:18 -0700 In-Reply-To: Mime-Version: 1.0 References: <20250619073136.506022-2-shivankg@amd.com> <20250619-fixpunkt-querfeldein-53eb22d0135f@brauner> <20250619-ablichten-korpulent-0efe2ddd0ee6@brauner> Message-ID: Subject: Re: [PATCH] fs: export anon_inode_make_secure_inode() and fix secretmem LSM bypass From: Sean Christopherson To: Mike Rapoport Cc: Christian Brauner , Vlastimil Babka , Shivank Garg , david@redhat.com, akpm@linux-foundation.org, paul@paul-moore.com, viro@zeniv.linux.org.uk, willy@infradead.org, pbonzini@redhat.com, tabba@google.com, afranji@google.com, ackerleytng@google.com, jack@suse.cz, hch@infradead.org, cgzones@googlemail.com, ira.weiny@intel.com, roypat@amazon.co.uk, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org Content-Type: text/plain; charset="us-ascii" X-Rspamd-Queue-Id: DBAF7C0026 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: f3q1sh6fjt4frei513yzbrjerxeond57 X-HE-Tag: 1750431743-743813 X-HE-Meta: U2FsdGVkX1+8LS8motM0nIzz5oiOBfZ7lmnW9KvENxAFaOgYLJRgaXg/OlM5zk78+jHbD9zDaoLoPiBT8dbf8W1H/FjQp3TeC3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NckQG4/wZ1YzTroRdzVDRWhaVFPin6gAkIN/+ptiiFiF5+pVHecC+0hsAfhSsH48s2F+dxHfJ399Bqqtar8E50iDRzyKhnjw9oiz3IsZv9qh4xs8rn3L2+yqsuWjYAtuljoyPSsdFoTkdfn0R9AedDiTeRgTVA0vEnFizTcU0+mCA0dOdjh0Ag7JAMpoSQZPEH9LpJEg9JX3voEYs41QEnOuVtZpuk/Yokenl6EIhrmm8ohF/KJrKmiDyfyD3b0zejazVJ2WIeOVlVqry+li+pvSI5Dh9UaeCq1BsJHD0+exw9wkie8yqCMtMeF+kJXaCYn5ZQk8XspF9unFpQgf6f1yVewvlaMKCvJicBSNO2rIR+M8PW+aeoyjE2/NM/XO5nmkR3yB3mO4kJCDWRJrvQgC8vwOPkeoilQ0fFWWFgu1UvNvc6nsUZ6GDzUrvKxukF5Z2GIjMOUyQtSQfKYFmg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Thu, Jun 19, 2025, Mike Rapoport wrote: > On Thu, Jun 19, 2025 at 02:06:17PM +0200, Christian Brauner wrote: > > On Thu, Jun 19, 2025 at 02:01:22PM +0300, Mike Rapoport wrote: > > > On Thu, Jun 19, 2025 at 12:38:25PM +0200, Christian Brauner wrote: > > > > On Thu, Jun 19, 2025 at 11:13:49AM +0200, Vlastimil Babka wrote: > > > > > On 6/19/25 09:31, Shivank Garg wrote: > > > > > > Export anon_inode_make_secure_inode() to allow KVM guest_memfd to create > > > > > > anonymous inodes with proper security context. This replaces the current > > > > > > pattern of calling alloc_anon_inode() followed by > > > > > > inode_init_security_anon() for creating security context manually. > > > > > > > > > > > > This change also fixes a security regression in secretmem where the > > > > > > S_PRIVATE flag was not cleared after alloc_anon_inode(), causing > > > > > > LSM/SELinux checks to be bypassed for secretmem file descriptors. > > > > > > > > > > > > As guest_memfd currently resides in the KVM module, we need to export this > > > > > > > > > > Could we use the new EXPORT_SYMBOL_GPL_FOR_MODULES() thingy to make this > > > > > explicit for KVM? > > > > > > > > Oh? Enlighten me about that, if you have a second, please. > > > > > > From Documentation/core-api/symbol-namespaces.rst: > > > > > > The macro takes a comma separated list of module names, allowing only those > > > modules to access this symbol. Simple tail-globs are supported. > > > > > > For example:: > > > > > > EXPORT_SYMBOL_GPL_FOR_MODULES(preempt_notifier_inc, "kvm,kvm-*") > > > > > > will limit usage of this symbol to modules whoes name matches the given > > > patterns. > > > > Is that still mostly advisory and can still be easily circumenvented? Yes and no. For out-of-tree modules, it's mostly advisory. Though I can imagine if someone tries to report a bug because their module is masquerading as e.g. kvm, then they will be told to go away (in far less polite words :-D). For in-tree modules, the restriction is much more enforceable. Renaming a module to circumvent a restricted export will raise major red flags, and getting "proper" access to a symbol would require an ack from the relevant maintainers. E.g. for many KVM-induced exports, it's not that other module writers are trying to misbehave, there simply aren't any guardrails to deter them from using a "dangerous" export. The other big benefit I see is documentation, e.g. both for readers/developers to understand the intent, and for auditing purposes (I would be shocked if there aren't exports that were KVM-induced, but that are no longer necessary). And we can utilize the framework to do additional hardening. E.g. for exports that exist solely for KVM, I plan on adding wrappers so that the symbols are exproted if and only if KVM is enabled in the kernel .config[*]. Again, that's far from perfect, e.g. AFAIK every distro enables KVM, but it should help keep everyone honest. [*] https://lore.kernel.org/all/ZzJOoFFPjrzYzKir@google.com > The commit message says > > will limit the use of said function to kvm.ko, any other module trying > to use this symbol will refure to load (and get modpost build > failures). To Christian's point, the restrictions are trivial to circumvent by out-of-tree modules. E.g. to get access to the above, simply name your module kvm-lol.ko or whatever.