From patchwork Thu Jan 30 15:23:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerhard Heift X-Patchwork-Id: 3557811 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 71499C02DC for ; Thu, 30 Jan 2014 15:24:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B4A1920123 for ; Thu, 30 Jan 2014 15:24:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 35E71201C8 for ; Thu, 30 Jan 2014 15:24:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753441AbaA3PYQ (ORCPT ); Thu, 30 Jan 2014 10:24:16 -0500 Received: from mail-ee0-f54.google.com ([74.125.83.54]:46537 "EHLO mail-ee0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752636AbaA3PYP (ORCPT ); Thu, 30 Jan 2014 10:24:15 -0500 Received: by mail-ee0-f54.google.com with SMTP id e53so1688911eek.27 for ; Thu, 30 Jan 2014 07:24:13 -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=ISTFZsGM408AGohkmT1Kpjkc7mm8EY9rYLVgahdMqm8=; b=WZm/wGyhRl8vRdDETFWrhYkqEiH8UipvE2exk4oqOlg2zsuCz05lpVnWlc7jSRRVJu Ac68A164ySp56FbhCBNDhfcGrTHLwxNIW03nme7haizplwka3pf8ane+ZojOPqP3np9n efz+EM2iJeZQNZa9uZaEB3DGYwDK3rLrFzaYPbDLTKCnEJYNyp5GF9L1P3cOQt8X6Eic kqtl5ZiZ+MW9bVyo+mE+L1wHpHWFUYB6eYw8xdBZPZQoqCRhnE7V7fPUj3UOdyngzEyI MANYURNUOqbly52tbVHDj4AopAKzozBNCXsUmg02Stwgc5w31KAnZUCPwGplgtavi+Yn hPbw== X-Gm-Message-State: ALoCoQmibYBOwjfaHcSEUQMvoxHOk0kAcDQXwvzxidKoGa2pFrGeZppAuFNCXeXBiIG5IlIX1E0I X-Received: by 10.14.216.3 with SMTP id f3mr3107746eep.66.1391095453796; Thu, 30 Jan 2014 07:24:13 -0800 (PST) Received: from localhost (host-115-115.kawo1.rwth-aachen.de. [134.130.115.115]) by mx.google.com with ESMTPSA id v1sm23649582eef.9.2014.01.30.07.24.12 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 30 Jan 2014 07:24:13 -0800 (PST) From: Gerhard Heift To: linux-btrfs@vger.kernel.org Subject: [PATCH RFCv4 2/7] btrfs: tree_search, search_ioctl: accept varying buffer Date: Thu, 30 Jan 2014 16:23:58 +0100 Message-Id: <1391095443-20287-3-git-send-email-Gerhard@Heift.Name> X-Mailer: git-send-email 1.8.5.3 In-Reply-To: <1391095443-20287-1-git-send-email-Gerhard@Heift.Name> References: <1391095443-20287-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.3 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 b1c5b4f..9b66eac 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 out; } @@ -1937,17 +1937,21 @@ out: } 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; @@ -1981,7 +1985,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) @@ -2010,7 +2014,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);