Received: by 10.223.185.116 with SMTP id b49csp1098558wrg; Fri, 23 Feb 2018 11:55:20 -0800 (PST) X-Google-Smtp-Source: AH8x226/A6g5jLy0K84TnRmUDUKyy6tvDorcRy2HnGOEdsVr75ZBAeLxA7wHs/amicv7fr4/HJM7 X-Received: by 2002:a17:902:24a5:: with SMTP id w34-v6mr2645829pla.221.1519415720211; Fri, 23 Feb 2018 11:55:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519415720; cv=none; d=google.com; s=arc-20160816; b=hDlkzvFvk8PMTvL7c7R4+78XYBwQfWLw0/RqvpeWfOG4bCn2p6DepIwKhPIzyQOeCi 3npoUgoEAVDHcKQgXnNaf87lgJfP7Xg9fI1z/4piyOV0EXAATPBRksZnv9B9aFbXra4y vHyhYxT0ZW0OLDjEyhZx4LfoM7bWyPT+tuhNRgcS7nuzBT6oxWGh0ZtDzydBwPdqaDVd vKC1PvRtplMxz5l+mndlJWnRhB+GGIdAApU/3Q9hkpw0mK1uUHhs5qYTkZl5FMRpZeK2 wzDO02FUT4NZknuA8YGRE2fT2EiLePw36zEls3i9PLPCfkKvedEk5e7kYp0Tg06ducmY fWDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=EoElfQNSVu7x4DhvXeoTGaAClC6jDl9swcn6j4JgQoQ=; b=vkEsOZdRhbZclWyT4Md97R9xr/v40kjI3B8fRtocvOlnEIUhhqILhYFxYAb50lxwjH fNFhaxIv5FI+stMJPP2Jih8t3hxEvO2Gp5V1GGUVzl6cRS765iorMX2/6sEi++iNzeS4 NJAFJxvQ6MqxXG249YTdvMWYSKrbGArsaTMnwx1hv0Tt2EuEp07AV28+H9aSoRORYJ/4 hKm/1MnUUGyLPZfS4R1ua4E4ET+y77sV7QlFEBz5uwO/gXNoKsfFrQHTmG1mW2oJ83eN Esh3rJVNsoCMrHY/93sR9OFoqJQq8cBTuSbRJYY+DfmePxeIVl4rtE0qRGeOxIkQ6G1u odmg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e2si1867798pgr.242.2018.02.23.11.55.05; Fri, 23 Feb 2018 11:55:20 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933474AbeBWTyb (ORCPT + 99 others); Fri, 23 Feb 2018 14:54:31 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:43228 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933731AbeBWSpK (ORCPT ); Fri, 23 Feb 2018 13:45:10 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 5794E122E; Fri, 23 Feb 2018 18:45:09 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nikolay Borisov , David Sterba , Sasha Levin Subject: [PATCH 4.9 067/145] btrfs: Fix possible off-by-one in btrfs_search_path_in_tree Date: Fri, 23 Feb 2018 19:26:13 +0100 Message-Id: <20180223170733.329401059@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170724.669759283@linuxfoundation.org> References: <20180223170724.669759283@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Nikolay Borisov [ Upstream commit c8bcbfbd239ed60a6562964b58034ac8a25f4c31 ] The name char array passed to btrfs_search_path_in_tree is of size BTRFS_INO_LOOKUP_PATH_MAX (4080). So the actual accessible char indexes are in the range of [0, 4079]. Currently the code uses the define but this represents an off-by-one. Implications: Size of btrfs_ioctl_ino_lookup_args is 4096, so the new byte will be written to extra space, not some padding that could be provided by the allocator. btrfs-progs store the arguments on stack, but kernel does own copy of the ioctl buffer and the off-by-one overwrite does not affect userspace, but the ending 0 might be lost. Kernel ioctl buffer is allocated dynamically so we're overwriting somebody else's memory, and the ioctl is privileged if args.objectid is not 256. Which is in most cases, but resolving a subvolume stored in another directory will trigger that path. Before this patch the buffer was one byte larger, but then the -1 was not added. Fixes: ac8e9819d71f907 ("Btrfs: add search and inode lookup ioctls") Signed-off-by: Nikolay Borisov Reviewed-by: David Sterba [ added implications ] Signed-off-by: David Sterba Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2244,7 +2244,7 @@ static noinline int btrfs_search_path_in if (!path) return -ENOMEM; - ptr = &name[BTRFS_INO_LOOKUP_PATH_MAX]; + ptr = &name[BTRFS_INO_LOOKUP_PATH_MAX - 1]; key.objectid = tree_id; key.type = BTRFS_ROOT_ITEM_KEY;