Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2366807imm; Mon, 28 May 2018 06:50:33 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqUt7EVPXhPLvR4XT+tNHyNbmc7ANJIjk1wZArOGU73zLTqFWGQs4aRZFui+l3N2K0FYDfC X-Received: by 2002:a65:5308:: with SMTP id m8-v6mr10967558pgq.42.1527515433814; Mon, 28 May 2018 06:50:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527515433; cv=none; d=google.com; s=arc-20160816; b=hjWLNVijWMZKTi/rUU6sZquKubLl4lAu3OFXuYUbGaV+bVcsNr1W4gqZmMNFGV59fq 0+oFUt6oM8Qt+QSDuoguabLKkoKeFm8xFtwrNf3j+PQVAHmLIREMvU3Ngf4DmefvW5oW SDn5fIiRMXEM6NPVpf4lpodORLuEZBitUy4I97UDa7NWkfZZUhLiRMSP6QX4kSmXxU/M Iddak8rpfduwZsccY/c7Mp5x++YvJbo7r9wLrC/AYcLJpzfVx3oGfw1WbOP9V7vSCPaa fyU5VOJ7aBnGEDC6ErwPLH8lluPqJqune71FCm1QAGuwtVknWzIRHTVVm7TxrLMoH563 EjZQ== 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:dkim-signature :arc-authentication-results; bh=j3YLDUk/O4KcdM94cZW1qEIBJo2VIphgwyR1SLf1CAA=; b=Oe8EA1BpLTXAUtulAisovVnlmV/Y4jNLThNuel+p09hcZvjuoU4QwUqZvkFnn9eSoa Xecakzi1HrvEsIhz2gpSi6/c5EyeQ8l4uXycEVXNco4C1ENbNKA/lBgHeSbeyb/dTvCt bBmyXr+jdZq6XvaMkCj45eiGPnpyZkQULQjE9siFjW8+scqLtjMEIfVA6CO1kG+4OniH Yu8gbnzxZlIZyn+OLWJWQXjOpbuYvUk5l1yoStcIbTGTKKNECV0XsEZ3+UPFn4AcRUdC Q1IZ6w+ew/sNKgUluaIsiUKXrvBGr2F0v5+5NA8mWJttgWBd09rgGY/ClYOxJM8mswI9 aHGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=X3XBxvpF; 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 t127-v6si23216102pgc.519.2018.05.28.06.50.19; Mon, 28 May 2018 06:50:33 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=X3XBxvpF; 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 S937417AbeE1KmM (ORCPT + 99 others); Mon, 28 May 2018 06:42:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:33468 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S937423AbeE1KmF (ORCPT ); Mon, 28 May 2018 06:42:05 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EE719208A2; Mon, 28 May 2018 10:42:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527504124; bh=zqAiBAj4eKLe75Rx/xGsJ3PMWMQrtBLW1CoXs4uE6gE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X3XBxvpFV8ygXLYVtK2/i4Zv/FK9GfU1ZWBFg4OLA9ZLnJsPG5ZK2GCnw2k0tfuen tPH2ZRKbbPAb5YNRt44/mKKs6/SuwK+7DSnuKVifyQMifMaggtp2VyTxorSLkr/HwV KwckkkQbM2s3TplQVsXIL0kHZso42vEumeAbOYVE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+35666cba7f0a337e2e79@syzkaller.appspotmail.com, Matthew Wilcox , Andrew Morton , Linus Torvalds Subject: [PATCH 4.14 022/496] idr: fix invalid ptr dereference on item delete Date: Mon, 28 May 2018 11:56:47 +0200 Message-Id: <20180528100320.536610380@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100319.498712256@linuxfoundation.org> References: <20180528100319.498712256@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.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Matthew Wilcox commit 7a4deea1aa8bddfed4ef1b35fc2b6732563d8ad5 upstream. If the radix tree underlying the IDR happens to be full and we attempt to remove an id which is larger than any id in the IDR, we will call __radix_tree_delete() with an uninitialised 'slot' pointer, at which point anything could happen. This was easiest to hit with a single entry at id 0 and attempting to remove a non-0 id, but it could have happened with 64 entries and attempting to remove an id >= 64. Roman said: The syzcaller test boils down to opening /dev/kvm, creating an eventfd, and calling a couple of KVM ioctls. None of this requires superuser. And the result is dereferencing an uninitialized pointer which is likely a crash. The specific path caught by syzbot is via KVM_HYPERV_EVENTD ioctl which is new in 4.17. But I guess there are other user-triggerable paths, so cc:stable is probably justified. Matthew added: We have around 250 calls to idr_remove() in the kernel today. Many of them pass an ID which is embedded in the object they're removing, so they're safe. Picking a few likely candidates: drivers/firewire/core-cdev.c looks unsafe; the ID comes from an ioctl. drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c is similar drivers/atm/nicstar.c could be taken down by a handcrafted packet Link: http://lkml.kernel.org/r/20180518175025.GD6361@bombadil.infradead.org Fixes: 0a835c4f090a ("Reimplement IDR and IDA using the radix tree") Reported-by: Debugged-by: Roman Kagan Signed-off-by: Matthew Wilcox Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- lib/radix-tree.c | 4 +++- tools/testing/radix-tree/idr-test.c | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) --- a/lib/radix-tree.c +++ b/lib/radix-tree.c @@ -2037,10 +2037,12 @@ void *radix_tree_delete_item(struct radi unsigned long index, void *item) { struct radix_tree_node *node = NULL; - void __rcu **slot; + void __rcu **slot = NULL; void *entry; entry = __radix_tree_lookup(root, index, &node, &slot); + if (!slot) + return NULL; if (!entry && (!is_idr(root) || node_tag_get(root, node, IDR_FREE, get_slot_offset(node, slot)))) return NULL; --- a/tools/testing/radix-tree/idr-test.c +++ b/tools/testing/radix-tree/idr-test.c @@ -202,6 +202,13 @@ void idr_checks(void) idr_remove(&idr, 3); idr_remove(&idr, 0); + assert(idr_alloc(&idr, DUMMY_PTR, 0, 0, GFP_KERNEL) == 0); + idr_remove(&idr, 1); + for (i = 1; i < RADIX_TREE_MAP_SIZE; i++) + assert(idr_alloc(&idr, DUMMY_PTR, 0, 0, GFP_KERNEL) == i); + idr_remove(&idr, 1 << 30); + idr_destroy(&idr); + for (i = INT_MAX - 3UL; i < INT_MAX + 1UL; i++) { struct item *item = item_create(i, 0); assert(idr_alloc(&idr, item, i, i + 10, GFP_KERNEL) == i);