From patchwork Thu Nov 6 11:05:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerhard Heift X-Patchwork-Id: 5240971 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 3073BC11AC for ; Thu, 6 Nov 2014 11:06:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 217CB200F0 for ; Thu, 6 Nov 2014 11:06:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6F61F200E0 for ; Thu, 6 Nov 2014 11:06:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750974AbaKFLF4 (ORCPT ); Thu, 6 Nov 2014 06:05:56 -0500 Received: from mail-lb0-f169.google.com ([209.85.217.169]:47710 "EHLO mail-lb0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750926AbaKFLFz (ORCPT ); Thu, 6 Nov 2014 06:05:55 -0500 Received: by mail-lb0-f169.google.com with SMTP id 10so700031lbg.28 for ; Thu, 06 Nov 2014 03:05:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=DevorwAAnc4tdc39KTOk4rvjGNN94Lbq6a93y3NZbng=; b=C322KpiY0cVa1uvCOqgVKf32q+ZToa8FvIwT6M3wDYlOrvbrAg0UGYd3sO5CvIAeFB 5nPxEfUaK/A7xIKDC/WDx2SuOtnbhDrjr+eXjt4Gi1yJqNqC348YjT0/fmytu3Mq0Vu7 GM7f3FxoVMXYjAn2a5mz52wKOAJL0llHi04j+VE7A7byiHnHcg/Tv67ooyWAJy1FZ8Ov tsAH2vXGksN1+iPUX5t/mmWcI9/Kfbhcb+XErR0xOfATXoKhX9lwyRfWQayY5m8dxVps ugnhfNx10LyyNfDcF60nfft5jEm1t4n/WMyAyDb5ekNicQXBqJjT50xi3IgmWoszZ0E1 2FXA== X-Gm-Message-State: ALoCoQn/241C2t2B/X1T45NSSeWVLn35WB0o5oYfbyOQghZisf8NeGtSdHXVChs5nLgnQDMsqDAX MIME-Version: 1.0 X-Received: by 10.112.162.101 with SMTP id xz5mr4042011lbb.49.1415271952985; Thu, 06 Nov 2014 03:05:52 -0800 (PST) Received: by 10.112.132.6 with HTTP; Thu, 6 Nov 2014 03:05:52 -0800 (PST) X-Originating-IP: [84.63.31.103] In-Reply-To: <201411061743.5znDnvlg%fengguang.wu@intel.com> References: <201411061743.5znDnvlg%fengguang.wu@intel.com> Date: Thu, 6 Nov 2014 12:05:52 +0100 Message-ID: Subject: Re: fs/btrfs/ioctl.c:2204:29: sparse: incorrect type in argument 4 (different address spaces) From: Gerhard Heift To: Chris Mason Cc: kbuild-all@01.org, linux-btrfs@vger.kernel.org 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.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_TVD_MIME_EPI, 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 Hello, I got a warning from the kbuild test robot for an invalid address space cast, which was introduced by my patch for TREE_SEARCH_V2. Here is a patch, which should fix the warning. Regards, Gerhard 2014-11-06 10:48 GMT+01:00 kbuild test robot : > tree: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master > head: 20f3963d8f48ae8309fbc777ef6787fd0a3f53c2 > commit: cc68a8a5a4330a4bb72922d0c7a7044ae13ee692 btrfs: new ioctl TREE_SEARCH_V2 > date: 5 months ago > reproduce: > # apt-get install sparse > git checkout cc68a8a5a4330a4bb72922d0c7a7044ae13ee692 > make ARCH=x86_64 allmodconfig > make C=1 CF=-D__CHECK_ENDIAN__ > > > sparse warnings: (new ones prefixed by >>) > > fs/btrfs/ioctl.c:2204:29: sparse: cast removes address space of expression >>> fs/btrfs/ioctl.c:2204:29: sparse: incorrect type in argument 4 (different address spaces) > fs/btrfs/ioctl.c:2204:29: expected char [noderef] *ubuf > fs/btrfs/ioctl.c:2204:29: got char * > fs/btrfs/ioctl.c:2729:27: sparse: incorrect type in assignment (different base types) > fs/btrfs/ioctl.c:2729:27: expected unsigned int [unsigned] [usertype] nodesize > fs/btrfs/ioctl.c:2729:27: got restricted __le32 [usertype] nodesize > fs/btrfs/ioctl.c:2730:29: sparse: incorrect type in assignment (different base types) > fs/btrfs/ioctl.c:2730:29: expected unsigned int [unsigned] [usertype] sectorsize > fs/btrfs/ioctl.c:2730:29: got restricted __le32 [usertype] sectorsize > fs/btrfs/ioctl.c:2731:34: sparse: incorrect type in assignment (different base types) > fs/btrfs/ioctl.c:2731:34: expected unsigned int [unsigned] [usertype] clone_alignment > fs/btrfs/ioctl.c:2731:34: got restricted __le32 [usertype] sectorsize > fs/btrfs/ioctl.c:4275:29: sparse: incorrect type in argument 1 (different address spaces) > fs/btrfs/ioctl.c:4275:29: expected void [noderef] *to > fs/btrfs/ioctl.c:4275:29: got void * > fs/btrfs/ioctl.c:4350:29: sparse: incorrect type in argument 1 (different address spaces) > fs/btrfs/ioctl.c:4350:29: expected void [noderef] *to > fs/btrfs/ioctl.c:4350:29: got void * > > vim +2204 fs/btrfs/ioctl.c > > 2188 /* copy search header and buffer size */ > 2189 uarg = (struct btrfs_ioctl_search_args_v2 __user *)argp; > 2190 if (copy_from_user(&args, uarg, sizeof(args))) > 2191 return -EFAULT; > 2192 > 2193 buf_size = args.buf_size; > 2194 > 2195 if (buf_size < sizeof(struct btrfs_ioctl_search_header)) > 2196 return -EOVERFLOW; > 2197 > 2198 /* limit result size to 16MB */ > 2199 if (buf_size > buf_limit) > 2200 buf_size = buf_limit; > 2201 > 2202 inode = file_inode(file); > 2203 ret = search_ioctl(inode, &args.key, &buf_size, >> 2204 (char *)(&uarg->buf[0])); > 2205 if (ret == 0 && copy_to_user(&uarg->key, &args.key, sizeof(args.key))) > 2206 ret = -EFAULT; > 2207 else if (ret == -EOVERFLOW && > 2208 copy_to_user(&uarg->buf_size, &buf_size, sizeof(buf_size))) > 2209 ret = -EFAULT; > 2210 > 2211 return ret; > 2212 } > > --- > 0-DAY kernel test infrastructure Open Source Technology Center > http://lists.01.org/mailman/listinfo/kbuild Intel Corporation From 620ff16527bd711e7b6677ba7d5ecfb4467c231a Mon Sep 17 00:00:00 2001 From: Gerhard Heift Date: Thu, 6 Nov 2014 11:30:10 +0100 Subject: [PATCH] btrfs: fix address space cast in TREE_SEARCH_V2 This patches fixes an invalid cast of an user space address to kernel space, but is still used as user space in the called function. This cast would have not been necessary, if I had choosen the type of (struct btrfs_ioctl_search_args_v2).buf as char[] and not as __u64[], which I did for for unknown reasons. Signed-off-by: Gerhard Heift --- fs/btrfs/ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 6ea1546..dbd577e 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2201,7 +2201,7 @@ static noinline int btrfs_ioctl_tree_search_v2(struct file *file, inode = file_inode(file); ret = search_ioctl(inode, &args.key, &buf_size, - (char *)(&uarg->buf[0])); + (char __user *)(&uarg->buf[0])); if (ret == 0 && copy_to_user(&uarg->key, &args.key, sizeof(args.key))) ret = -EFAULT; else if (ret == -EOVERFLOW && -- 2.1.1