From patchwork Sat Jan 18 00:15:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerhard Heift X-Patchwork-Id: 3507651 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 23455C02DC for ; Sat, 18 Jan 2014 00:16:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 56D2C2017D for ; Sat, 18 Jan 2014 00:16:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7DDE72017B for ; Sat, 18 Jan 2014 00:16:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752742AbaARAQS (ORCPT ); Fri, 17 Jan 2014 19:16:18 -0500 Received: from mail-ee0-f53.google.com ([74.125.83.53]:37205 "EHLO mail-ee0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752699AbaARAQR (ORCPT ); Fri, 17 Jan 2014 19:16:17 -0500 Received: by mail-ee0-f53.google.com with SMTP id t10so2367543eei.26 for ; Fri, 17 Jan 2014 16:16:16 -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=uk8xrjM7zJkN9opZnp16QDolheuOGX3oeM5w4csnA30=; b=eCCK1NDjmM4ezLBRM/n2kGt9to4yRuOpxH8McMV5HCkDi1908YmhGdv1G0WaR1P4T0 bXiFKLtsqI+ESrNOakFHlIGCls6O9C4pV/3aMuU7N92eGtj3qadd6/mlt1RDFu9h5qNI 1nyOf4TS+tX7qb6uj1wb9t9pseUGY/TOyH/n7ZvxZfQ5Hgj1fNJt4H8TFxPjGTk4eMrF jTt2XdaxlFaQixerhlKafoetuxUEwAIC/jzH/Pqm1Neq6+Cf/i7m/tWygbLgJbLvLNvf kQ1bGTZhLdExlmt7rigdU2NQegxM/P1e67XtMU0HUmXKH4crpdwxtaAmDit0vEQY/xTd TKEg== X-Gm-Message-State: ALoCoQlVak6o9JXA2iAInbZ3aL5UZk2UlSW+FCjxCbe8nBCipCLx6YEmHweZzYJjM+KicTBEJdQM X-Received: by 10.15.43.10 with SMTP id w10mr5425840eev.13.1390004176185; Fri, 17 Jan 2014 16:16:16 -0800 (PST) Received: from localhost (host-115-115.kawo1.rwth-aachen.de. [134.130.115.115]) by mx.google.com with ESMTPSA id x2sm28157733eeo.8.2014.01.17.16.16.15 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 17 Jan 2014 16:16:15 -0800 (PST) From: Gerhard Heift To: linux-btrfs@vger.kernel.org Subject: [PATCH RFC 1/5] btrfs: search_ioctl accepts varying buffer Date: Sat, 18 Jan 2014 01:15:49 +0100 Message-Id: <1390004153-4228-2-git-send-email-Gerhard@Heift.Name> X-Mailer: git-send-email 1.8.5.3 In-Reply-To: <1390004153-4228-1-git-send-email-Gerhard@Heift.Name> References: <20140116150710.GL6498@suse.cz> <1390004153-4228-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.2 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 | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 3970f32..be4c780 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1850,6 +1850,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) @@ -1882,11 +1883,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; } @@ -1931,17 +1931,22 @@ 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; @@ -1975,7 +1980,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) @@ -2004,7 +2009,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);