From patchwork Mon Dec 8 03:40:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 5453941 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 D95119F30B for ; Mon, 8 Dec 2014 03:42:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1DEFF2011E for ; Mon, 8 Dec 2014 03:42:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C0A2920142 for ; Mon, 8 Dec 2014 03:42:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753925AbaLHDl5 (ORCPT ); Sun, 7 Dec 2014 22:41:57 -0500 Received: from mail-pa0-f52.google.com ([209.85.220.52]:60732 "EHLO mail-pa0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753896AbaLHDlw (ORCPT ); Sun, 7 Dec 2014 22:41:52 -0500 Received: by mail-pa0-f52.google.com with SMTP id eu11so4385548pac.11 for ; Sun, 07 Dec 2014 19:41:52 -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=RyX8KvE259hhYAAmEdGhVAZnLeuNKPSOTWDaurxhO60=; b=EGusR39WuVmAC1UXxty+Xxqw+o/1uAHBdgnb+NBvLt0e0q1P+pqK7L+AY7BGV2BrFe IsywlGNI99x+4HLWq50QeyZwbn88vLq2kX+akwO+e+NaVrgBf595pVhMYZTzijmOI+Jj OoWeu/9eSRWYvNYCHQ2y852KobZRTutKAapgM1XOIh3cb/GpKyk8fQVfagBk3Yr0vE+S sX9ey1BJelngR2gr2bSTrykPbJaDMe1ccbwr1PpSDUECSrtMKSFTlhUnHCQISxKwQNmP iP6YrjoJFuWdbg+lxwI8Xvlrn6CN1pdBvIP9bgzR3colVv93swv3RkF6eRP7ePAj33cz mnCA== X-Gm-Message-State: ALoCoQmT6L9yPdVkgqcOyxpQYNKLjUdWu4J9sbOB2O4xAzSGF3bwQBYwNeESjtGayyNt5lOU/Irz X-Received: by 10.66.66.135 with SMTP id f7mr48661567pat.81.1418010112022; Sun, 07 Dec 2014 19:41:52 -0800 (PST) Received: from mew.localdomain (c-24-19-133-29.hsd1.wa.comcast.net. [24.19.133.29]) by mx.google.com with ESMTPSA id w5sm35041043pds.25.2014.12.07.19.41.49 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 07 Dec 2014 19:41:51 -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 v8 3/3] btrfs: fix suspicious RCU in BTRFS_IOC_DEV_INFO Date: Sun, 7 Dec 2014 19:40:59 -0800 Message-Id: <77dcc43b8e3dd20b1994b8e978008800e8dcf6b7.1418007402.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 9ebc3cc..324be12 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2734,6 +2734,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)) @@ -2754,17 +2755,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);