Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752265AbbDRKEp (ORCPT ); Sat, 18 Apr 2015 06:04:45 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:12252 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751835AbbDRKEn (ORCPT ); Sat, 18 Apr 2015 06:04:43 -0400 X-AuditID: cbfee61a-f79516d000006302-1f-55322c3936f8 From: Chao Yu To: Jaegeuk Kim , Changman Lee Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] f2fs: make posix_acl_create() safer and cleaner Date: Sat, 18 Apr 2015 18:03:58 +0800 Message-id: <007b01d079bf$1473eb40$3d5bc1c0$@samsung.com> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-index: AdB5vtu9RoPCn/wmQqy+FLolgC86vQ== Content-language: zh-cn X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrELMWRmVeSWpSXmKPExsVy+t9jQV1LHaNQg0OnRCyu7Wtksniyfhaz xaVF7haXd81hc2Dx2LSqk81j94LPTB59W1YxenzeJBfAEsVlk5Kak1mWWqRvl8CV8eT/beaC zwIV79fVNjAu5e1i5OSQEDCReP7lPwuELSZx4d56ti5GLg4hgemMEv+7/zFCOK8YJS5u72QD qWITUJFY3vGfCcQWEfCSmLT/BFg3s4CHRGPHd1YQW1jARaKncQUziM0ioCqxbvcdsDivgKXE 99YL7BC2oMSPyfegerUk1u88zgRhy0tsXvOWGeIiBYkdZ18zQuzSk/h/bRVUvbjExiO3WCYw CsxCMmoWklGzkIyahaRlASPLKkbR1ILkguKk9FxDveLE3OLSvHS95PzcTYzgkH4mtYNxZYPF IUYBDkYlHt4brw1DhVgTy4orcw8xSnAwK4nwblQwChXiTUmsrEotyo8vKs1JLT7EKM3BoiTO O0dXLlRIID2xJDU7NbUgtQgmy8TBKdXAWJLxOnyawoFlK61rzz7MjHm5xXXOPge1C8zGvwTT Nv9Vlaxa/7RctKg3z9uKf67boblNtzZbJ/EHf73iLNAfwtP9NPuB92c9K71MVwPVw/854hUm y3+YGuI4fcE+3oWT6uoatn6/s7a3hOUPQ2PvN5tzU7pLfu9yXDFxh7WKb/0T47g5B3IOKrEU ZyQaajEXFScCALwDGhBlAgAA Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2313 Lines: 100 Our f2fs_acl_create is copied from posix_acl_create in ./fs/posix_acl.c and modified to avoid deadlock bug when inline_dentry feature is enabled. Dan Carpenter rewrites posix_acl_create in commit 2799563b281f ("fs/posix_acl.c: make posix_acl_create() safer and cleaner") to make this function more safer, so that we can avoid potential bug in its caller, especially for ocfs2. Let's back port the patch to f2fs. Signed-off-by: Chao Yu --- fs/f2fs/acl.c | 46 ++++++++++++++++++++-------------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/fs/f2fs/acl.c b/fs/f2fs/acl.c index 4320ffa..c8f25f7 100644 --- a/fs/f2fs/acl.c +++ b/fs/f2fs/acl.c @@ -334,51 +334,45 @@ static int f2fs_acl_create(struct inode *dir, umode_t *mode, struct page *dpage) { struct posix_acl *p; + struct posix_acl *clone; int ret; + *acl = NULL; + *default_acl = NULL; + if (S_ISLNK(*mode) || !IS_POSIXACL(dir)) - goto no_acl; + return 0; p = __f2fs_get_acl(dir, ACL_TYPE_DEFAULT, dpage); - if (IS_ERR(p)) { - if (p == ERR_PTR(-EOPNOTSUPP)) - goto apply_umask; - return PTR_ERR(p); + if (!p || p == ERR_PTR(-EOPNOTSUPP)) { + *mode &= ~current_umask(); + return 0; } + if (IS_ERR(p)) + return PTR_ERR(p); - if (!p) - goto apply_umask; - - *acl = f2fs_acl_clone(p, GFP_NOFS); - if (!*acl) + clone = f2fs_acl_clone(p, GFP_NOFS); + if (!clone) goto no_mem; - ret = f2fs_acl_create_masq(*acl, mode); + ret = f2fs_acl_create_masq(clone, mode); if (ret < 0) goto no_mem_clone; - if (ret == 0) { - posix_acl_release(*acl); - *acl = NULL; - } + if (ret == 0) + posix_acl_release(clone); + else + *acl = clone; - if (!S_ISDIR(*mode)) { + if (!S_ISDIR(*mode)) posix_acl_release(p); - *default_acl = NULL; - } else { + else *default_acl = p; - } - return 0; -apply_umask: - *mode &= ~current_umask(); -no_acl: - *default_acl = NULL; - *acl = NULL; return 0; no_mem_clone: - posix_acl_release(*acl); + posix_acl_release(clone); no_mem: posix_acl_release(p); return -ENOMEM; -- 2.3.3 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/