Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp367059imm; Thu, 10 May 2018 22:41:25 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqL1sK8U3o4adjvfvJ+Js67aMqDWuyYG5CMAYp8JewsuC9S/Vg12a+Yrb9ipgY/UMvdcLow X-Received: by 2002:a63:894a:: with SMTP id v71-v6mr3413064pgd.423.1526017285910; Thu, 10 May 2018 22:41:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526017285; cv=none; d=google.com; s=arc-20160816; b=nPLLlM+SYvb0DTG3mUAN29J4F972k3YBkYdbfJbYqsQrA6XQGf4WDPCQgyacECQcdB S7sVIz1IhQEwwL4/7ct1eJ6K+dHN8r1aTe1KpfZmW3OihELSQkaCGwBoskzLdRdk9Wsl pubNjkW6CY24uPMLd2OhDc+ATT1JEUs81sCsJiEf3Z2rSO0+bGSgWnzyj/a4/oq7IrcL 4HIm+OfE2gfX849vFk36KVTvGQID6Lku4RQgLcGGOs55rRZ4+7phURPj3nhiVIvkaeZE gkj0D698yvOugwnolnObpUjmmqFN30xiU9tJ4Y6Kmof2QFTQ1cvnbS/keXtQzmt0nkNN 9uPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=OCcij5lfwm2lBJQ8IRrrWV7Yrqo9bSs3SDlQD4UWeyc=; b=nbxVu6WFsP2bHb2NhQ/iqhsguD5wngxZfo967TONULdpO+veArSPUvU/eXqBYOzPQ7 M10wnCtcuZe5wYslhCX9K03KEOJ2DCYa/ipGeOIRbsXHjTbHTPFxW3TlOpuvUqF+UBYe /yMBAIuPd4a/ZxnYopH6tJa2jmGi008LU3Sb35YHNGywAD3J/rL5MywgdWTt3++Hu6TB eQ3Cmc51W1SEYTCC/NcX+m9TrgXhYBDqxQhuawQurFlMgosGD9bOYIerkyXxsbvNkugm BQ0dwMmxqtQ8gWcZnc1xdEbPC+RKjLyQfMYg4385WGjg0ZmaJ88/n7jgZCPDsNHe75zd GppA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=wRmHbmLp; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y11-v6si2624129plt.455.2018.05.10.22.40.59; Thu, 10 May 2018 22:41:25 -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=@google.com header.s=20161025 header.b=wRmHbmLp; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752209AbeEKFku (ORCPT + 99 others); Fri, 11 May 2018 01:40:50 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:36648 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751430AbeEKFks (ORCPT ); Fri, 11 May 2018 01:40:48 -0400 Received: by mail-pl0-f66.google.com with SMTP id v24-v6so2654554plo.3 for ; Thu, 10 May 2018 22:40:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=OCcij5lfwm2lBJQ8IRrrWV7Yrqo9bSs3SDlQD4UWeyc=; b=wRmHbmLpa5miSAAKZTyNvHi7LY7vMpmoAVqGyqhATsoMy/gmZwK/cWrdhU7JYNe/aN DenI4lk6eCSTrTb1KlHtgrNKYbjnMd52jUfs9Z/WiCC8vXBAS88RJApI+zF06/pjtDa1 6TlbnSybPRI8piFOmvlh+E24/rBeIo2exTMFIYXVcZlFqvUE28tpcWCUOfGUfn24unJE b7SF/VisqLuOBfjP9KcTw3gEQrk666MypnGdHhnMNz4BgXw9IhqCVJgAxwtK70bnRsZ0 ZD/O7s7NWGeav6iXDH6fvZ2e9R1r0UE1QgM2PNlJ6Yb3I5T9tpYEHxG3s0Im65V9CPNO i9Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=OCcij5lfwm2lBJQ8IRrrWV7Yrqo9bSs3SDlQD4UWeyc=; b=hnDqgpevlzl2u7CGvP5qmcsN9UW4zXCQGTre6vuB6djfyCIpGJBczHL0OZ/Pd3kt5p NvN5OTJrbrIbGh9okqSwBkMxgFdZ2wF7oF/DrfcUwsa4mil4KYZDdcBtW9WvUS/S3GYS ZEB964pJvyEAW23CyUjKwhBayKbvc2WM/g4F2wAjvzmxsPwbFYd+C9r53vgHp1Gz9TL0 3JtbxHSNKdgwjzkrTBQOKbkOtQNFIZMu6+ZjYZt2AzidixQCTuFscIh53Kp5LLPfRRC6 P3FUYP1i9T69KzvLuRaRSmeP6xyB/cvFuQn1wjYy7ilNKuFjfCcq1zV11aeI0V+4+HH8 ymyw== X-Gm-Message-State: ALKqPweb4bgpIyd6vo0Jtd9NbNEgoudzC9in1aI1gspgUX66R5sO6Dx8 8WIovTqNO0d9SoYkeYwle0WYk92oZR4DTowgfE0O3g== X-Received: by 2002:a17:902:2a43:: with SMTP id i61-v6mr4238191plb.54.1526017247261; Thu, 10 May 2018 22:40:47 -0700 (PDT) MIME-Version: 1.0 Received: by 10.236.149.24 with HTTP; Thu, 10 May 2018 22:40:26 -0700 (PDT) In-Reply-To: <52bd5b0b-a4bb-5426-3c92-edd7085faea3@redhat.com> References: <20180510191634.18796-1-rkagan@virtuozzo.com> <52bd5b0b-a4bb-5426-3c92-edd7085faea3@redhat.com> From: Dmitry Vyukov Date: Fri, 11 May 2018 07:40:26 +0200 Message-ID: Subject: Re: [PATCH] idr: fix invalid ptr dereference on item delete To: Paolo Bonzini Cc: Roman Kagan , Matthew Wilcox , syzbot , "H. Peter Anvin" , KVM list , LKML , Ingo Molnar , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , syzkaller-bugs , Thomas Gleixner , "the arch/x86 maintainers" , Cathy Avery , stable 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 On Fri, May 11, 2018 at 1:54 AM, Paolo Bonzini wrote: > On 10/05/2018 21:16, Roman Kagan wrote: >> If an IDR contains a single entry at index==0, the underlying radix tree >> has a single item in its root node, in which case >> __radix_tree_lookup(index!=0) doesn't set its *@nodep argument (in >> addition to returning NULL). >> >> However, the tree itself is not empty, i.e. the tree root doesn't have >> IDR_FREE tag. >> >> As a result, on an attempt to remove an index!=0 entry from such an IDR, >> radix_tree_delete_item doesn't return early and calls >> __radix_tree_delete with invalid parameters which are then dereferenced. >> >> Reported-by: syzbot+35666cba7f0a337e2e79@syzkaller.appspotmail.com >> Signed-off-by: Roman Kagan >> --- >> lib/radix-tree.c | 5 +++-- >> 1 file changed, 3 insertions(+), 2 deletions(-) >> >> diff --git a/lib/radix-tree.c b/lib/radix-tree.c >> index da9e10c827df..10ff1bfae952 100644 >> --- a/lib/radix-tree.c >> +++ b/lib/radix-tree.c >> @@ -2040,8 +2040,9 @@ void *radix_tree_delete_item(struct radix_tree_root *root, >> void *entry; >> >> entry = __radix_tree_lookup(root, index, &node, &slot); >> - if (!entry && (!is_idr(root) || node_tag_get(root, node, IDR_FREE, >> - get_slot_offset(node, slot)))) >> + if (!entry && (!is_idr(root) || !node || >> + node_tag_get(root, node, IDR_FREE, >> + get_slot_offset(node, slot)))) >> return NULL; >> >> if (item && entry != item) >> > > I cannot really vouch for the patch, but if it is correct it's > definitely stuff for stable. The KVM testcase is only for 4.17-rc but > this is a really nasty bug in a core data structure. > > Cc: stable@vger.kernel.org > > Should radix-tree be compilable in userspace, so that we can add unit > tests for it?... Good point. For my education, what/where are the tests that run as user-space code?