From patchwork Thu Oct 10 17:39:28 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 3017731 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 CE52E9F245 for ; Thu, 10 Oct 2013 17:40:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A2600202FF for ; Thu, 10 Oct 2013 17:40:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7F8C0202BE for ; Thu, 10 Oct 2013 17:40:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756322Ab3JJRj7 (ORCPT ); Thu, 10 Oct 2013 13:39:59 -0400 Received: from mail-ee0-f51.google.com ([74.125.83.51]:43355 "EHLO mail-ee0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755686Ab3JJRj7 (ORCPT ); Thu, 10 Oct 2013 13:39:59 -0400 Received: by mail-ee0-f51.google.com with SMTP id c1so1330686eek.10 for ; Thu, 10 Oct 2013 10:39: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; bh=I2CjeIRc/xiT9wjp8kQ4uRRrde3JJkk/msgoEeNCCLU=; b=jUpG4eEisl1Pq54fed5J1ERHuWQX8ZDCPK/cS07iNia+GWSbXTkVtGFs+OBCKd6QlB ZCpuocdm3FL1Vr01xVjV2H6loLoeqvI5FHJ2HZTPseGJboMVXJISTSA1H76mUxb2Oao4 kF5SPEv90O82RAtS8Tr9Mxv8GEzo7r0VW7+yySOeHeoQBjndVwkSbTw4Ie+ecIWZ5jBG 8MoMSWGTyAl9biNGTln/9NO2gHljSbDKdttpQfzAd3SR6qp5Hyv5JJY+BTkzIOpUM/Qm Z6ciewpuNoZiFR+4J3iaHGlrbCyrosOP/OG7r8DvDNSHp4lXaEGNf5Fz9NjZWeMv1CrU SIFg== X-Received: by 10.14.4.1 with SMTP id 1mr22427586eei.21.1381426798144; Thu, 10 Oct 2013 10:39:58 -0700 (PDT) Received: from localhost ([109.110.75.198]) by mx.google.com with ESMTPSA id k7sm104160364eeg.13.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 10 Oct 2013 10:39:57 -0700 (PDT) From: Ilya Dryomov To: linux-btrfs@vger.kernel.org Cc: Chris Mason , idryomov@gmail.com Subject: [PATCH] Btrfs: don't leak ioctl args in btrfs_ioctl_dev_replace Date: Thu, 10 Oct 2013 20:39:28 +0300 Message-Id: <1381426768-31904-1-git-send-email-idryomov@gmail.com> X-Mailer: git-send-email 1.7.10.4 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.0 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 struct btrfs_ioctl_dev_replace_args memory is leaked if replace is requested on a read-only filesystem. Fix it. Signed-off-by: Ilya Dryomov --- fs/btrfs/ioctl.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 9d46f60..17bb98e 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -3679,9 +3679,10 @@ static long btrfs_ioctl_dev_replace(struct btrfs_root *root, void __user *arg) switch (p->cmd) { case BTRFS_IOCTL_DEV_REPLACE_CMD_START: - if (root->fs_info->sb->s_flags & MS_RDONLY) - return -EROFS; - + if (root->fs_info->sb->s_flags & MS_RDONLY) { + ret = -EROFS; + goto out; + } if (atomic_xchg( &root->fs_info->mutually_exclusive_operation_running, 1)) { @@ -3707,7 +3708,7 @@ static long btrfs_ioctl_dev_replace(struct btrfs_root *root, void __user *arg) if (copy_to_user(arg, p, sizeof(*p))) ret = -EFAULT; - +out: kfree(p); return ret; }