From patchwork Wed Apr 22 03:50:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boqun Feng X-Patchwork-Id: 6254501 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2A74ABF4A6 for ; Wed, 22 Apr 2015 03:51:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3829E2034F for ; Wed, 22 Apr 2015 03:51:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 51E7C20306 for ; Wed, 22 Apr 2015 03:51:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756994AbbDVDuz (ORCPT ); Tue, 21 Apr 2015 23:50:55 -0400 Received: from mail-pa0-f50.google.com ([209.85.220.50]:35741 "EHLO mail-pa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756986AbbDVDuv (ORCPT ); Tue, 21 Apr 2015 23:50:51 -0400 Received: by pabtp1 with SMTP id tp1so260575787pab.2; Tue, 21 Apr 2015 20:50:51 -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=wRgx266RuYWnzU6g2WXSkIKVjxr/QUmKgC8kl3vhnwM=; b=fqsbg5Ioq6IHSJN5UwsEZonETe2J2w3LySAD+meGLp7weQyPiXdsP/okJnFfd5trmh kwf0u2YuegOuPLZ+9HASTLy+/rTSohjvuAyIC2IqiIqZIgLH78hbgRiK3yCqLEreSk8f nKvAcKC1oGHGXQEY5uMPei+H//ac7/i2VlvFAIoUsllNWEbN4wKyZXaAQjR4dzbe8/EH jNsNGnOJKSWh2GNG2hG97/0k8Cnyr6aJlZt1U2b3uj0jlnxqYqGNEw2bU4RFT9tI6CCC UODgMpdBmEdEMYzJ7zKbFiJvfCRPRcmH3laQKZNS0X3r5th+4pUC9gcZGrOiTToLOaAJ 1XXg== X-Received: by 10.68.106.226 with SMTP id gx2mr18106201pbb.78.1429674651099; Tue, 21 Apr 2015 20:50:51 -0700 (PDT) Received: from localhost ([162.243.141.196]) by mx.google.com with ESMTPSA id q3sm3486982pds.49.2015.04.21.20.50.48 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Apr 2015 20:50:49 -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 1/2] vfs: export symbol 'getname' and 'putname' Date: Wed, 22 Apr 2015 11:50:23 +0800 Message-Id: <1429674624-25922-2-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 getname/putname in fs/namei.c is a well-implemented way to copy a file name from userland, however other ways, such as directly calling __getname() and strncpy_from_user(), may lack features(e.g. auditing and reusing), introduce errors or at least reinvent wheels. Therefore for places need a kernel file name copy from userland, it's better to use getname and putname if possible. To be able to use these functions all over the kernel, symbols 'getname' and 'putname' are exported and comments of their behaviors and constraints are added. Suggested-by: Al Viro Signed-off-by: Boqun Feng --- fs/namei.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/fs/namei.c b/fs/namei.c index c83145a..472911c 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -199,11 +199,23 @@ error: return err; } +/** + * getname() - Get a file name copy from userland + * @filename: userland pointer to the file name + * + * If successful, return a 'struct filename' pointer and ->name is the pointer + * to the kernel copy of the file name, otherwise an ERR_PTR. + * + * getname() should only be called in a system call context, and for each + * getname() that returns a successful value, callers must ensure exactly one + * corresponding putname() is called before returning to userland. + */ struct filename * getname(const char __user * filename) { return getname_flags(filename, 0, NULL); } +EXPORT_SYMBOL(getname); struct filename * getname_kernel(const char * filename) @@ -242,6 +254,11 @@ getname_kernel(const char * filename) return result; } +/* putname() - Release a 'struct filename' structure + * @name: the 'struct filename' structure to be release + * + * See more at getname() + */ void putname(struct filename *name) { BUG_ON(name->refcnt <= 0); @@ -255,6 +272,7 @@ void putname(struct filename *name) } else __putname(name); } +EXPORT_SYMBOL(putname); static int check_acl(struct inode *inode, int mask) {