From patchwork Thu Jan 30 00:27:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerhard Heift X-Patchwork-Id: 3555421 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BFC9F9F2E9 for ; Thu, 30 Jan 2014 00:28:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 007BF2018E for ; Thu, 30 Jan 2014 00:28:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 025F2201BA for ; Thu, 30 Jan 2014 00:28:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752311AbaA3A1z (ORCPT ); Wed, 29 Jan 2014 19:27:55 -0500 Received: from mail-ee0-f42.google.com ([74.125.83.42]:49212 "EHLO mail-ee0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752188AbaA3A1r (ORCPT ); Wed, 29 Jan 2014 19:27:47 -0500 Received: by mail-ee0-f42.google.com with SMTP id e49so1264045eek.1 for ; Wed, 29 Jan 2014 16:27:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=nXXDpooGRhiV967CM30RTOt+kbwhMCMvOIsEhV8jL+A=; b=hNH8mCwnbXFsULfhgHLj8x4AFhAM2cs0VtNWv8tOT396eledaYiCnZsjFL9IpePTiU gpyDI74GpMX+6VXfRmbieq6B1bsihsOHzUUq0W+/fFGFS0DpWKHI0xhGz7G3uHF9muIP olrA9eXzi4tbSfBl1T/eLCYYhx1MbC1gaajazsgSjA9dgdZ320Dauy5gKFI4fW8AqMfp hJgme/ymBsqYWnMGvb+2sPI3URkLf/kc8ERIoe++WXfWnaY8fSKEwy75OpsrWFLdrMLg Jzd5tcQWj8lX7rpuAjetdIANVq6oS2cEac7qWEh+FGfe+LsMuHQBgJvPGtsFbeSP/3b6 f2tw== X-Gm-Message-State: ALoCoQkSEH/BfVHUoJFY6zhDh8J24u4A29BuC7CY5FLfhohTZ9httC+YXLHF+fPw3/TRqv6312i7 X-Received: by 10.14.200.135 with SMTP id z7mr58546een.110.1391041666617; Wed, 29 Jan 2014 16:27:46 -0800 (PST) Received: from localhost (host-115-115.kawo1.rwth-aachen.de. [134.130.115.115]) by mx.google.com with ESMTPSA id b41sm15386495eef.16.2014.01.29.16.27.45 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 29 Jan 2014 16:27:45 -0800 (PST) From: Gerhard Heift To: linux-btrfs@vger.kernel.org Subject: [PATCH RFCv3 1/6] btrfs: search_ioctl accepts varying buffer Date: Thu, 30 Jan 2014 01:27:26 +0100 Message-Id: <1391041651-15689-2-git-send-email-Gerhard@Heift.Name> X-Mailer: git-send-email 1.8.5.3 In-Reply-To: <1391041651-15689-1-git-send-email-Gerhard@Heift.Name> References: <1391041651-15689-1-git-send-email-Gerhard@Heift.Name> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 rewrite search_ioctl to accept a buffer with varying size Signed-off-by: Gerhard Heift --- fs/btrfs/ioctl.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 34772cb..6aa79e0 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1854,6 +1854,7 @@ static noinline int copy_to_sk(struct btrfs_root *root, struct btrfs_path *path, struct btrfs_key *key, struct btrfs_ioctl_search_key *sk, + size_t buf_size, char *buf, unsigned long *sk_offset, int *num_found) @@ -1886,11 +1887,10 @@ static noinline int copy_to_sk(struct btrfs_root *root, if (!key_in_sk(key, sk)) continue; - if (sizeof(sh) + item_len > BTRFS_SEARCH_ARGS_BUFSIZE) + if (sizeof(sh) + item_len > buf_size) item_len = 0; - if (sizeof(sh) + item_len + *sk_offset > - BTRFS_SEARCH_ARGS_BUFSIZE) { + if (sizeof(sh) + item_len + *sk_offset > buf_size) { ret = 1; goto overflow; } @@ -1935,17 +1935,21 @@ overflow: } static noinline int search_ioctl(struct inode *inode, - struct btrfs_ioctl_search_args *args) + struct btrfs_ioctl_search_key *sk, + size_t buf_size, + char *buf) { struct btrfs_root *root; struct btrfs_key key; struct btrfs_path *path; - struct btrfs_ioctl_search_key *sk = &args->key; struct btrfs_fs_info *info = BTRFS_I(inode)->root->fs_info; int ret; int num_found = 0; unsigned long sk_offset = 0; + if (buf_size < sizeof(struct btrfs_ioctl_search_header)) + return -EOVERFLOW; + path = btrfs_alloc_path(); if (!path) return -ENOMEM; @@ -1979,7 +1983,7 @@ static noinline int search_ioctl(struct inode *inode, ret = 0; goto err; } - ret = copy_to_sk(root, path, &key, sk, args->buf, + ret = copy_to_sk(root, path, &key, sk, buf_size, buf, &sk_offset, &num_found); btrfs_release_path(path); if (ret || num_found >= sk->nr_items) @@ -2008,7 +2012,7 @@ static noinline int btrfs_ioctl_tree_search(struct file *file, return PTR_ERR(args); inode = file_inode(file); - ret = search_ioctl(inode, args); + ret = search_ioctl(inode, &args->key, sizeof(args->buf), args->buf); if (ret == 0 && copy_to_user(argp, args, sizeof(*args))) ret = -EFAULT; kfree(args);