From patchwork Wed Apr 22 03:50:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boqun Feng X-Patchwork-Id: 6254491 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 738219F1C4 for ; Wed, 22 Apr 2015 03:51:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 88D492035B for ; Wed, 22 Apr 2015 03:51:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5BD7920306 for ; Wed, 22 Apr 2015 03:51:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757021AbbDVDvE (ORCPT ); Tue, 21 Apr 2015 23:51:04 -0400 Received: from mail-ig0-f172.google.com ([209.85.213.172]:32839 "EHLO mail-ig0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757009AbbDVDu6 (ORCPT ); Tue, 21 Apr 2015 23:50:58 -0400 Received: by igbpi8 with SMTP id pi8so97286500igb.0; Tue, 21 Apr 2015 20:50:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=00qoOE4+WOqbJbhGxsimxThPnKVJolLQ0GB8sqN6Y3M=; b=EqXRzTDUTc1jN7p1ddv6IrpsaYRk3mnBFk76o6F7VkD7Uw5RhsXIqEJzlbAbC3AZBr PFw8fIeoykMgV3IyAPrGFS39pjIKKEPbaDgLZMNT01YWCKsB/2FrnfxFuX7K7NkfuJuE a9qf95iXIveR/2BWqOMgQpIXjtWXlQbYzFT7psEZ47NJ5Wirh/wem2Alj4c1/0ylNX0Q faF77rzPnBcFy3mYI0TAHklsd2855aPSue8ixS0IqN7VyY91GlbpIUXEYDunSCW6YHOp +M3XPmEOsveLk0VXqRLkuz55TzLyG97MVyDynf3GDCOQTTwoSMWKRIn2O5lTDkBa3TWS pS9Q== X-Received: by 10.107.9.141 with SMTP id 13mr33786686ioj.71.1429674658074; Tue, 21 Apr 2015 20:50:58 -0700 (PDT) Received: from localhost ([162.243.141.196]) by mx.google.com with ESMTPSA id b8sm2401454ioe.23.2015.04.21.20.50.55 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Apr 2015 20:50:56 -0700 (PDT) From: Boqun Feng To: linux-fsdevel@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Cc: Boqun Feng , Al Viro , Oleg Drokin , Andreas Dilger , Greg Kroah-Hartman , Jan Kara Subject: [PATCH 2/2] staging: lustre: replace ll_{get, put}name() with {get, put}name() Date: Wed, 22 Apr 2015 11:50:24 +0800 Message-Id: <1429674624-25922-3-git-send-email-boqun.feng@gmail.com> X-Mailer: git-send-email 2.3.5 In-Reply-To: <1429674624-25922-1-git-send-email-boqun.feng@gmail.com> References: <1429674624-25922-1-git-send-email-boqun.feng@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP As pointed by Al Viro: https://lkml.org/lkml/2015/4/11/243 There are bugs in ll_getname() because of wrong assumptions of returning values from strncpy_from_user(). Moreover, what ll_getname want to do is just to try copy the file name from userland. Since we already have getname() for the same purpose, it's better to replace ll_getname() with getname(), so is ll_putname(). Besides, remove unused code for checking whether namelen is 0 or not in case LL_IOC_REMOVE_ENTRY, because zero-length file name is already handled by getname() in the same way as ll_getname(). Suggested-by: Al Viro Signed-off-by: Boqun Feng Reviewed-by: Andreas Dilger --- drivers/staging/lustre/lustre/llite/dir.c | 60 ++++++---------------- .../staging/lustre/lustre/llite/llite_internal.h | 2 +- drivers/staging/lustre/lustre/llite/namei.c | 2 +- 3 files changed, 18 insertions(+), 46 deletions(-) diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c index a182019..c75fc38 100644 --- a/drivers/staging/lustre/lustre/llite/dir.c +++ b/drivers/staging/lustre/lustre/llite/dir.c @@ -1216,30 +1216,6 @@ out: return rc; } -static char * -ll_getname(const char __user *filename) -{ - int ret = 0, len; - char *tmp = __getname(); - - if (!tmp) - return ERR_PTR(-ENOMEM); - - len = strncpy_from_user(tmp, filename, PATH_MAX); - if (len == 0) - ret = -ENOENT; - else if (len > PATH_MAX) - ret = -ENAMETOOLONG; - - if (ret) { - __putname(tmp); - tmp = ERR_PTR(ret); - } - return tmp; -} - -#define ll_putname(filename) __putname(filename) - static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct inode *inode = file_inode(file); @@ -1441,7 +1417,7 @@ free_lmv: return rc; } case LL_IOC_REMOVE_ENTRY: { - char *filename = NULL; + struct filename *name = NULL; int namelen = 0; int rc; @@ -1453,20 +1429,16 @@ free_lmv: if (!(exp_connect_flags(sbi->ll_md_exp) & OBD_CONNECT_LVB_TYPE)) return -ENOTSUPP; - filename = ll_getname((const char *)arg); - if (IS_ERR(filename)) - return PTR_ERR(filename); + name = getname((const char *)arg); + if (IS_ERR(name)) + return PTR_ERR(name); - namelen = strlen(filename); - if (namelen < 1) { - rc = -EINVAL; - goto out_rmdir; - } + namelen = strlen(name->name); + + rc = ll_rmdir_entry(inode, name->name, namelen); - rc = ll_rmdir_entry(inode, filename, namelen); -out_rmdir: - if (filename) - ll_putname(filename); + if (name) + putname(name); return rc; } case LL_IOC_LOV_SWAP_LAYOUTS: @@ -1481,16 +1453,16 @@ out_rmdir: struct lov_user_md *lump; struct lov_mds_md *lmm = NULL; struct mdt_body *body; - char *filename = NULL; + struct filename *name = NULL; int lmmsize; if (cmd == IOC_MDC_GETFILEINFO || cmd == IOC_MDC_GETFILESTRIPE) { - filename = ll_getname((const char *)arg); - if (IS_ERR(filename)) - return PTR_ERR(filename); + name = getname((const char *)arg); + if (IS_ERR(name)) + return PTR_ERR(name); - rc = ll_lov_getstripe_ea_info(inode, filename, &lmm, + rc = ll_lov_getstripe_ea_info(inode, name->name, &lmm, &lmmsize, &request); } else { rc = ll_dir_getstripe(inode, &lmm, &lmmsize, &request); @@ -1556,8 +1528,8 @@ skip_lmm: out_req: ptlrpc_req_finished(request); - if (filename) - ll_putname(filename); + if (name) + putname(name); return rc; } case IOC_LOV_GETINFO: { diff --git a/drivers/staging/lustre/lustre/llite/llite_internal.h b/drivers/staging/lustre/lustre/llite/llite_internal.h index 2af1d72..0950565 100644 --- a/drivers/staging/lustre/lustre/llite/llite_internal.h +++ b/drivers/staging/lustre/lustre/llite/llite_internal.h @@ -714,7 +714,7 @@ struct inode *ll_iget(struct super_block *sb, ino_t hash, int ll_md_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *, void *data, int flag); struct dentry *ll_splice_alias(struct inode *inode, struct dentry *de); -int ll_rmdir_entry(struct inode *dir, char *name, int namelen); +int ll_rmdir_entry(struct inode *dir, const char *name, int namelen); /* llite/rw.c */ int ll_prepare_write(struct file *, struct page *, unsigned from, unsigned to); diff --git a/drivers/staging/lustre/lustre/llite/namei.c b/drivers/staging/lustre/lustre/llite/namei.c index 890ac19..ec48d8d 100644 --- a/drivers/staging/lustre/lustre/llite/namei.c +++ b/drivers/staging/lustre/lustre/llite/namei.c @@ -867,7 +867,7 @@ static inline void ll_get_child_fid(struct dentry *child, struct lu_fid *fid) /** * Remove dir entry **/ -int ll_rmdir_entry(struct inode *dir, char *name, int namelen) +int ll_rmdir_entry(struct inode *dir, const char *name, int namelen) { struct ptlrpc_request *request = NULL; struct md_op_data *op_data;