From patchwork Sun Nov 30 08:26:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 5407351 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 D5B6EBEEA8 for ; Sun, 30 Nov 2014 08:28:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 06FE520121 for ; Sun, 30 Nov 2014 08:28:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2889520120 for ; Sun, 30 Nov 2014 08:28:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751996AbaK3I2P (ORCPT ); Sun, 30 Nov 2014 03:28:15 -0500 Received: from mail-pa0-f44.google.com ([209.85.220.44]:46351 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751994AbaK3I1B (ORCPT ); Sun, 30 Nov 2014 03:27:01 -0500 Received: by mail-pa0-f44.google.com with SMTP id et14so9132321pad.17 for ; Sun, 30 Nov 2014 00:27:01 -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:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=CnJgvXUIvOcvo3tXam0cOHOShexrRcOfvs4ab70i5ws=; b=byQqna6Zz0+5KnNZpFKxjZe2enOKHNAibWQ0PH2apirm6/2vuNVGqlWw9kvOrZBxUP Z6y3ZZED0uIA7SxY2PPteHNi9R+1T0Er1A08Wziq7fDwNmCyLE5LBx53Ojedtcf9JEsR aW/+jBv/2quf/aNly0OyS9DV8gAHI+r7xLqwh3m0o4YmjTiL2iSzRYSeLEtsjpCkostE Gm6qHum8nSq4jvIljTVi91ewKkK6oC/jsYH6V6cXob+y/MXalueJKW8U8DfSZDcjxev9 YZQXkjGmWYMKd/C0PhJqdBnDWl+S9VTZpU3lO1LY+PWghMhKfFAqVzyyikKIeZlDdhUw 13uQ== X-Gm-Message-State: ALoCoQnhUHNdBqEMLOB4gS1M6qqMjIzWdecAnsDAG9M2cnPs5LrBhxedqhk2vqr5DUUSni3j1DUY X-Received: by 10.68.218.231 with SMTP id pj7mr86786510pbc.163.1417336020926; Sun, 30 Nov 2014 00:27:00 -0800 (PST) Received: from mew.localdomain ([72.192.100.38]) by mx.google.com with ESMTPSA id k10sm14383316pdm.3.2014.11.30.00.26.59 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 30 Nov 2014 00:27:00 -0800 (PST) From: Omar Sandoval To: Chris Mason , Josef Bacik , Joe Perches , "Paul E. McKenney" , Josh Triplett , Steven Rostedt , Mathieu Desnoyers , linux-kernel@vger.kernel.org, linux-btrfs@vger.kernel.org Cc: Omar Sandoval Subject: [PATCH 2/3] btrfs: fix suspicious RCU in BTRFS_IOC_DEV_INFO Date: Sun, 30 Nov 2014 00:26:48 -0800 Message-Id: <6566ef127f0d7ad4d33dd90362dd76e431359ef8.1417335583.git.osandov@osandov.com> X-Mailer: git-send-email 2.1.3 In-Reply-To: References: In-Reply-To: References: Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_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 A naked read of the value of an RCU pointer isn't safe. Put the whole access in an RCU critical section, not just the pointer dereference. Signed-off-by: Omar Sandoval --- fs/btrfs/ioctl.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index ecdf68f..dd55844 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2706,6 +2706,7 @@ static long btrfs_ioctl_dev_info(struct btrfs_root *root, void __user *arg) struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices; int ret = 0; char *s_uuid = NULL; + struct rcu_string *name; di_args = memdup_user(arg, sizeof(*di_args)); if (IS_ERR(di_args)) @@ -2726,17 +2727,16 @@ static long btrfs_ioctl_dev_info(struct btrfs_root *root, void __user *arg) di_args->bytes_used = btrfs_device_get_bytes_used(dev); di_args->total_bytes = btrfs_device_get_total_bytes(dev); memcpy(di_args->uuid, dev->uuid, sizeof(di_args->uuid)); - if (dev->name) { - struct rcu_string *name; - rcu_read_lock(); - name = rcu_dereference(dev->name); + rcu_read_lock(); + name = rcu_dereference(dev->name); + if (name) { strncpy(di_args->path, name->str, sizeof(di_args->path)); - rcu_read_unlock(); di_args->path[sizeof(di_args->path) - 1] = 0; } else { di_args->path[0] = '\0'; } + rcu_read_unlock(); out: mutex_unlock(&fs_devices->device_list_mutex);