Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2177501rdb; Thu, 7 Dec 2023 23:45:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IFOSJlM5gNVxjgauF4PhHJ23nbrCjGkqxXfUnN2TkAyxpEKICnKTogr1YN7oOrrVz5VQiyy X-Received: by 2002:a05:6a21:3288:b0:18b:51e:e711 with SMTP id yt8-20020a056a21328800b0018b051ee711mr3991789pzb.13.1702021555136; Thu, 07 Dec 2023 23:45:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702021555; cv=none; d=google.com; s=arc-20160816; b=x3ZNSdiMfMNDPx47RaRqpERtL7cLw2biqMEAuP0rH/rYJ64BsuyWgz4ZS4n9krqqyH 7nYzSff3m3odCARRj4NIb8WRBwRCv4ySQz9UN74eSAWRI1VUln2/Z7QfN/GJPys1/2ze RUMC795fHTTOfMR/9WWuB7Lhvj6IJMT6xH4XQdJEFUnknHwouwi3XPdOV07ApUSF3mpI TZwVL+mmaELYaJOoYiE2+HiodxPslp2XKGeRieufXdhQFlwjkBIWnabOd5ndmFjB8Lcs TbbJQYkkueYFlUEWKb4gEzzVn8NVHXjnKbGvxRqyET6eJzapvEHuUURcdCXMJRDWmKsh gMyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:subject:message-id:in-reply-to:date :mime-version; bh=ZF23So3eTGy+0U3Y49QflHjA50Q1YjNpuWzkNe4lr8Q=; fh=V9AeBafJgTW96HdC48wsxGAfd7Fe9P2uAL8tLCjpUN4=; b=ybHW2jluKVEbtTXxa+RoNFH/HinBTYGy2eiUHCcpa+oPfPd590PAFsbmz2fCR6PEaY x7Jp0wTtJbM4CksdjUnnMqP+IGcZ5tjrsFTlnFKY9JXebi1ynjWwCeBnwGMHpy2P9NvD hJKGK93LujcwsGt/QrbZecXmzG8vn98tSm0OYPqLQ3gf1cv5bTmBgaxQc1N9fr/9lw0F RRlZxK6tOEgO7EekxJhSzoN7DIJhyfqBRkiILWC8ZL9gfpPD1BOVZGFLfaTvOOWF8t1V vdMu+xnDlhapf4BnwvBJ1gaL6v7IGScdOlNg0xjBjLMorjAT/8+HZzYwPID8r3pC7a3z /+ug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=appspotmail.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id p1-20020a63fe01000000b005c68b6c6b82si1086762pgh.747.2023.12.07.23.45.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 23:45:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=appspotmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id AE81F8077526; Thu, 7 Dec 2023 23:45:13 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573330AbjLHHoi (ORCPT + 99 others); Fri, 8 Dec 2023 02:44:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573325AbjLHHog (ORCPT ); Fri, 8 Dec 2023 02:44:36 -0500 Received: from mail-oa1-f70.google.com (mail-oa1-f70.google.com [209.85.160.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 195401720 for ; Thu, 7 Dec 2023 23:44:43 -0800 (PST) Received: by mail-oa1-f70.google.com with SMTP id 586e51a60fabf-1faef8466f9so3150795fac.3 for ; Thu, 07 Dec 2023 23:44:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702021482; x=1702626282; h=to:from:subject:message-id:in-reply-to:date:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZF23So3eTGy+0U3Y49QflHjA50Q1YjNpuWzkNe4lr8Q=; b=WGfkEvUPzOgVQvkVOIIHAlMZXsnktUPfRUB9P420Nf8gsxo3ZzIStwnkSCjOftJKiP VUH23XlV4JIYorJnoaUbCmxDH8mD5X3lg38mlPxq1EziLkiyj2xOS2afTpJat+3cQHp9 oWWDlFe0n/GHvx6LBRIWzFGnYLERXfrDG5r92LeFiRQSXXxqaMHTYn7yJ30OeHb5M7F1 jfNr879u8D1366+W2snscsvM9TAQZD3qFKNKtwdySrZLzpaATssAHb99XFvjESp0UFbj nt2K4IztawVtO8+lo9m2GIRmR6xt+luWsyggLdLCd8URIe4g/CglY2kAN18YhhWscqc0 AR0Q== X-Gm-Message-State: AOJu0YxYxcgOUQQTK5TNCQDtv6ecfzN7g/CTPrhTul3olSpjzz1OF1F3 Al84LLz+eYsJYdOeYz1YMJs6T14Sh8U2BJwr6fJ6ULarYdvA8b8= MIME-Version: 1.0 X-Received: by 2002:a05:6870:f62a:b0:1fb:f51:25bb with SMTP id ek42-20020a056870f62a00b001fb0f5125bbmr4441101oab.5.1702021482517; Thu, 07 Dec 2023 23:44:42 -0800 (PST) Date: Thu, 07 Dec 2023 23:44:42 -0800 In-Reply-To: <000000000000bfba3a060bf4ffcf@google.com> X-Google-Appengine-App-Id: s~syzkaller X-Google-Appengine-App-Id-Alias: syzkaller Message-ID: <000000000000dd9c39060bfac1fb@google.com> Subject: Re: [syzbot] [arm-msm?] [net?] memory leak in radix_tree_insert From: syzbot To: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.4 required=5.0 tests=FROM_LOCAL_HEX, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 07 Dec 2023 23:45:13 -0800 (PST) For archival purposes, forwarding an incoming command email to linux-kernel@vger.kernel.org. *** Subject: [arm-msm?] [net?] memory leak in radix_tree_insert Author: lizhi.xu@windriver.com #syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 33cc938e65a9 diff --git a/lib/radix-tree.c b/lib/radix-tree.c index 976b9bd02a1b..5c2f9d8f2c3e 100644 --- a/lib/radix-tree.c +++ b/lib/radix-tree.c @@ -581,6 +579,24 @@ static bool delete_node(struct radix_tree_root *root, return deleted; } +static bool __radix_tree_delete(struct radix_tree_root *root, + struct radix_tree_node *node, void __rcu **slot) +{ + void *old = rcu_dereference_raw(*slot); + int values = xa_is_value(old) ? -1 : 0; + unsigned offset = get_slot_offset(node, slot); + int tag; + + if (is_idr(root)) + node_tag_set(root, node, IDR_FREE, offset); + else + for (tag = 0; tag < RADIX_TREE_MAX_TAGS; tag++) + node_tag_clear(root, node, tag, offset); + + replace_slot(slot, NULL, node, -1, values); + return node && delete_node(root, node); +} + /** * __radix_tree_create - create a slot in a radix tree * @root: radix tree root @@ -714,8 +714,10 @@ int radix_tree_insert(struct radix_tree_root *root, unsigned long index, return error; error = insert_entries(node, slot, item); - if (error < 0) + if (error < 0) { + __radix_tree_delete(root, node, slot); return error; + } if (node) { unsigned offset = get_slot_offset(node, slot); @@ -1365,24 +1381,6 @@ radix_tree_gang_lookup_tag_slot(const struct radix_tree_root *root, } EXPORT_SYMBOL(radix_tree_gang_lookup_tag_slot); -static bool __radix_tree_delete(struct radix_tree_root *root, - struct radix_tree_node *node, void __rcu **slot) -{ - void *old = rcu_dereference_raw(*slot); - int values = xa_is_value(old) ? -1 : 0; - unsigned offset = get_slot_offset(node, slot); - int tag; - - if (is_idr(root)) - node_tag_set(root, node, IDR_FREE, offset); - else - for (tag = 0; tag < RADIX_TREE_MAX_TAGS; tag++) - node_tag_clear(root, node, tag, offset); - - replace_slot(slot, NULL, node, -1, values); - return node && delete_node(root, node); -} - /** * radix_tree_iter_delete - delete the entry at this iterator position * @root: radix tree root