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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16801C00528 for ; Sat, 8 Jul 2023 05:38:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233129AbjGHFiA (ORCPT ); Sat, 8 Jul 2023 01:38:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233013AbjGHFh3 (ORCPT ); Sat, 8 Jul 2023 01:37:29 -0400 Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB5E6268D for ; Fri, 7 Jul 2023 22:37:00 -0700 (PDT) Received: by mail-qt1-x82f.google.com with SMTP id d75a77b69052e-40339ce8470so21094701cf.0 for ; Fri, 07 Jul 2023 22:37:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore.com; s=google; t=1688794619; x=1691386619; h=in-reply-to:references:subject:cc:to:from:message-id:date:from:to :cc:subject:date:message-id:reply-to; bh=tGA1GMuiBFLQbBC9Kx/aFBaGS7w0xHkPHFkJJNA2iSI=; b=H4OjjGgTuSgh0ERbXj1XvS/xTBxkB7UvM7Vfkrh52Yu8LpFcioo23H7LN2pCGL4LW1 c0C5P5QmvB1fXe5I8JHSW7o4g1Ajl1MF/4+jjGWAydjxfqGvPpeQnueqoJppxuYX4Tib 6hoyeiTFlWTndTuwvK6ZBpbmb3kDElpYHJNNeVJBjWMXxzLWOzeNN55RmVFRtgUieiJS n9eYbXhSBN+H4R2tcet2YEN9vvVt5VousOwqJlNxxiBZVJ8WFLL0sPVVImmpWJYvuSnT MhL7JtJsQDdw8I3gZFN5WtS2gjWSOchAsKTG4rNTzlHCYSShijuEZjZzESlquH/iq7kj ueNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688794619; x=1691386619; h=in-reply-to:references:subject:cc:to:from:message-id:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tGA1GMuiBFLQbBC9Kx/aFBaGS7w0xHkPHFkJJNA2iSI=; b=I2Zh7h6thCRnlAxEi82vk2KjoU4nxfhd0gXI/jwAIBYtsJT5An0ww26sSHLmIlOjmU 3phGfN3LJnWGt4XjiajnJrDrMa+JOydpc7yNkaa5IyoeJYE5hcFV1pY93GTRXIg8DMVt 07WOVlXn1r94OE8wFx1ODXmJc6Hrng5ErJ7eWOYbzLyFHEIA/RYX3tgEzj8bmnN5ogXm wPKnpUpbjCMu2yCIKVSUIkwZ0OTj6v++oD4hItWPhVe0QBAurhVHGu17N4PBGLtSjEkQ I9KPGs/UxtqKogfTkeg7yPU5FFBGFVxFB8/Qx6gwbBDmk0HdN0iERiOJRvLu1C5ukwn4 jAgg== X-Gm-Message-State: ABy/qLaSpNvG0vD/9WHCT+1NI1kUIye7vKmAz512vz9qpjgRQuwqIJIH z8XH9EyXyYNljwBOagvlLtR6 X-Google-Smtp-Source: APBJJlFF68xKBlrT8ZUzDF7hUpibBBTXCy89LqgKEgf14OWs8qrR4aAL2DMHEseMAEOpXtlRbrYnOQ== X-Received: by 2002:ac8:7dc6:0:b0:3ff:2088:79d8 with SMTP id c6-20020ac87dc6000000b003ff208879d8mr9453816qte.4.1688794619449; Fri, 07 Jul 2023 22:36:59 -0700 (PDT) Received: from localhost ([70.22.175.108]) by smtp.gmail.com with ESMTPSA id a6-20020a0cca86000000b0062df126ca11sm2943696qvk.21.2023.07.07.22.36.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 22:36:59 -0700 (PDT) Date: Sat, 08 Jul 2023 01:36:58 -0400 Message-ID: <2edaa73fc9457f4a051115863d94b4ff.paul@paul-moore.com> From: Paul Moore To: Fan Wu , corbet@lwn.net, zohar@linux.ibm.com, jmorris@namei.org, serge@hallyn.com, tytso@mit.edu, ebiggers@kernel.org, axboe@kernel.dk, agk@redhat.com, snitzer@kernel.org, eparis@redhat.com Cc: linux-doc@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-block@vger.kernel.org, dm-devel@redhat.com, audit@vger.kernel.org, roberto.sassu@huawei.com, linux-kernel@vger.kernel.org, Fan Wu Subject: Re: [PATCH RFC v10 6/17] security: add new securityfs delete function References: <1687986571-16823-7-git-send-email-wufan@linux.microsoft.com> In-Reply-To: <1687986571-16823-7-git-send-email-wufan@linux.microsoft.com> Precedence: bulk List-ID: X-Mailing-List: linux-doc@vger.kernel.org On Jun 28, 2023 Fan Wu wrote: > > When deleting a directory in the security file system, the existing > securityfs_remove requires the directory to be empty, otherwise > it will do nothing. This leads to a potential risk that the security > file system might be in an unclean state when the intentded deletion > did not happen. > > This commit introduces a new function securityfs_recursive_remove > to recursively delete a directory without leaving an unclean state. > > Co-developed-by: "Christian Brauner (Microsoft)" > Signed-off-by: Fan Wu > --- > include/linux/security.h | 1 + > security/inode.c | 25 +++++++++++++++++++++++++ > 2 files changed, 26 insertions(+) > > diff --git a/include/linux/security.h b/include/linux/security.h > index e2734e9e44d5..a88076ebc7b1 100644 > --- a/include/linux/security.h > +++ b/include/linux/security.h > @@ -1971,6 +1971,7 @@ struct dentry *securityfs_create_symlink(const char *name, > const char *target, > const struct inode_operations *iops); > extern void securityfs_remove(struct dentry *dentry); > +extern void securityfs_recursive_remove(struct dentry *dentry); > > #else /* CONFIG_SECURITYFS */ > > diff --git a/security/inode.c b/security/inode.c > index 6c326939750d..13358e8547e8 100644 > --- a/security/inode.c > +++ b/security/inode.c > @@ -313,6 +313,31 @@ void securityfs_remove(struct dentry *dentry) > } > EXPORT_SYMBOL_GPL(securityfs_remove); > > +static void remove_one(struct dentry *victim) > +{ > + simple_release_fs(&mount, &mount_count); > +} > + > +/** > + * securityfs_recursive_remove - recursively removes a file or directory from the securityfs filesystem I really want to see lines less than or equal to 80 characters; I would suggest this: "securityfs_recursive_remove - recursively removes a file or directory" > + * @dentry: a pointer to a the dentry of the file or directory to be removed. > + * > + * This function recursively removes a file or directory in securityfs that was > + * previously created with a call to another securityfs function (like > + * securityfs_create_file() or variants thereof.) > + */ > +void securityfs_recursive_remove(struct dentry *dentry) > +{ > + if (IS_ERR_OR_NULL(dentry)) > + return; > + > + simple_pin_fs(&fs_type, &mount, &mount_count); > + simple_recursive_removal(dentry, remove_one); > + simple_release_fs(&mount, &mount_count); > +} > +EXPORT_SYMBOL_GPL(securityfs_recursive_remove); > + > #ifdef CONFIG_SECURITY > static struct dentry *lsm_dentry; > static ssize_t lsm_read(struct file *filp, char __user *buf, size_t count, > -- > 2.25.1 -- paul-moore.com