From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751417AbbHBKJO (ORCPT ); Sun, 2 Aug 2015 06:09:14 -0400 Received: from mail-wi0-f177.google.com ([209.85.212.177]:37749 "EHLO mail-wi0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750880AbbHBKJL (ORCPT ); Sun, 2 Aug 2015 06:09:11 -0400 Message-ID: <55bdec45.50ceb40a.3dcbf.fffff1b7@mx.google.com> From: Salvatore Mesoraca To: linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org Cc: James Morris , Al Viro , Salvatore Mesoraca Date: Sun, 2 Aug 2015 09:36:57 +0200 Subject: [PATCH] Adding return value to securityfs_remove. Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org "securityfs_remove" can fail if it tries to remove a non-empty directory. This can happen, for example, if it tries to remove a file and its parent directory while the file is busy: the file removal will be delayed and the directory removal will fail. This patch adds a return value to "securityfs_remove" so that the caller knows if it succeeded or not. Signed-off-by: Salvatore Mesoraca --- include/linux/security.h | 4 ++-- security/inode.c | 14 +++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index 79d85dd..ff022fc 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -1590,7 +1590,7 @@ extern struct dentry *securityfs_create_file(const char *name, umode_t mode, struct dentry *parent, void *data, const struct file_operations *fops); extern struct dentry *securityfs_create_dir(const char *name, struct dentry *parent); -extern void securityfs_remove(struct dentry *dentry); +extern int securityfs_remove(struct dentry *dentry); #else /* CONFIG_SECURITYFS */ @@ -1609,7 +1609,7 @@ static inline struct dentry *securityfs_create_file(const char *name, return ERR_PTR(-ENODEV); } -static inline void securityfs_remove(struct dentry *dentry) +static inline int securityfs_remove(struct dentry *dentry) {} #endif diff --git a/security/inode.c b/security/inode.c index 16622ae..41f42ea 100644 --- a/security/inode.c +++ b/security/inode.c @@ -183,28 +183,32 @@ EXPORT_SYMBOL_GPL(securityfs_create_dir); * This function is required to be called in order for the file to be * removed. No automatic cleanup of files will happen when a module is * removed; you are responsible here. + * + * Returns 0 if the remove succeeds, -errno on error. */ -void securityfs_remove(struct dentry *dentry) +int securityfs_remove(struct dentry *dentry) { + int ret = -EINVAL; struct dentry *parent; if (!dentry || IS_ERR(dentry)) - return; + return ret; parent = dentry->d_parent; if (!parent || d_really_is_negative(parent)) - return; + return ret; mutex_lock(&d_inode(parent)->i_mutex); if (simple_positive(dentry)) { if (d_is_dir(dentry)) - simple_rmdir(d_inode(parent), dentry); + ret = simple_rmdir(d_inode(parent), dentry); else - simple_unlink(d_inode(parent), dentry); + ret = simple_unlink(d_inode(parent), dentry); dput(dentry); } mutex_unlock(&d_inode(parent)->i_mutex); simple_release_fs(&mount, &mount_count); + return ret; } EXPORT_SYMBOL_GPL(securityfs_remove); -- 2.3.6