Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2161559rdb; Thu, 7 Dec 2023 23:01:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IFeFLVNLRbqlZ/7JLcTYHM6mRXiJzLnOtKA8v2tmBtxfmeRiSniOy0GNU+IFAW9jeRMqjB0 X-Received: by 2002:a05:6a00:198f:b0:6ce:91f6:2cb6 with SMTP id d15-20020a056a00198f00b006ce91f62cb6mr3385402pfl.63.1702018891121; Thu, 07 Dec 2023 23:01:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702018891; cv=none; d=google.com; s=arc-20160816; b=Zokdsnq+sQA+ykZwqhZdwnKrLD6+YQgi4B9mHJf3tfrkiXkn7KaODsp4wLUI9sYorA WNB1c1uMYaPyUj8N68SHJiMjEN8+mlzb11Kr3rmvdu8v8D5tMxTSjgIti22DneJAUW5/ j+0myy0Z3suIcTP/YhLWcmyk4h0EfHUcjCFBKLrkmCFqrSm6C/P99842IgB25araX/wA +muyIxuRHQG2R+XHzcn6CyvkaKSeA0Cf2sLndXQ7wj6UJr2iH3PkeZUAXMmYmZxMu/lv JQCVTQHkzSJzF2v55HfkswLyMGVhL6xnybSbMQzFLI+8vAah8+DniJ0L7GyO8DFpeuo6 76ag== 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=lOzqFhLXzpjBzeA1uOgLdaHhh/B0dFElnG9pBb+RYR0=; fh=V9AeBafJgTW96HdC48wsxGAfd7Fe9P2uAL8tLCjpUN4=; b=ruJ+Vp4je2M9IvCyl/mZb4pMNESx2FyDcEt5Bg/s744W7izYyc0K10qcei5TsBlcuW BbXoEpANJNFKz3dyWk0O9QSbzISdiJR6a2RCdjYaMBzdrKNJOmzWdpFsc1JVYZR+B1Ei 3n15y2YH/7yfQJcVwd0dLYCA+wvtbyDw17ozCWhnS+YFIZNUzzRNMawXRdTO+ziXXq8/ A4uZh/14RMduVx9TdHdoMkqkdUupBcrNYaZ3wM3LaB49Vei8Lo83A7VooRMkmmS3tGCH 70Rt0oLQuXrlxGxWkAj/irSSxI4JK/i05aoh5ZVLTgWhNF3MpevZfnMD7Kakqe/N3c88 SR+g== 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:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id bx2-20020a056a02050200b005bdf59618e3si1149326pgb.497.2023.12.07.23.01.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 23:01:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 8A40C8083DE0; Thu, 7 Dec 2023 23:00:37 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233340AbjLHG77 (ORCPT + 99 others); Fri, 8 Dec 2023 01:59:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235659AbjLHG7q (ORCPT ); Fri, 8 Dec 2023 01:59:46 -0500 Received: from mail-oa1-f69.google.com (mail-oa1-f69.google.com [209.85.160.69]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD2A619AE for ; Thu, 7 Dec 2023 22:59:49 -0800 (PST) Received: by mail-oa1-f69.google.com with SMTP id 586e51a60fabf-1fb34e3da36so2903851fac.1 for ; Thu, 07 Dec 2023 22:59:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702018789; x=1702623589; 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=lOzqFhLXzpjBzeA1uOgLdaHhh/B0dFElnG9pBb+RYR0=; b=vUhs2O2o2E6QeqhGwJxNu3ad/YGeGNy9WDmMmHBHqbg6u2kJyASefy0whKhR8JUel4 dwA+o/lVnlRYl7gVH1OJqyyDvxNt6npmuflNKsP1TjZYmNMirTkfggXqRlMzHDezlmGG 8zQRPCVgp9yOxqiL81cApoQtOF4gg1v9KJ5htuMFbAFCkCFtmASdyUwcMK8TEq8yRqLN zFO6F5ngyHSr17VZE6f3F1ed7QJYZxkl1B8ccnglJpd3NhbBHKPzJKRi32bvx1o41TQi LIIZCZb+vch3Q1YJvzIwOleMLFYg0qf/4m8Lz2qT8o3q4lB8xGbnVBjv77nKuwC6bF9W nDlA== X-Gm-Message-State: AOJu0Yx2zl9DhjuPSqnxqX3b82E3ANYp1TZAF4opDPczBnjsxkVCWq88 1IXWlkC1c0rBAvH14WoaTLrhESxm6yw2TI98X7w1zI6DmnpvsTA= MIME-Version: 1.0 X-Received: by 2002:a05:6870:ac08:b0:1fb:3bfc:a07e with SMTP id kw8-20020a056870ac0800b001fb3bfca07emr4618017oab.6.1702018789180; Thu, 07 Dec 2023 22:59:49 -0800 (PST) Date: Thu, 07 Dec 2023 22:59:49 -0800 In-Reply-To: <000000000000bfba3a060bf4ffcf@google.com> X-Google-Appengine-App-Id: s~syzkaller X-Google-Appengine-App-Id-Alias: syzkaller Message-ID: <000000000000548be3060bfa2154@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=1.1 required=5.0 tests=FROM_LOCAL_HEX, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SORBS_WEB, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Thu, 07 Dec 2023 23:00:38 -0800 (PST) X-Spam-Level: * 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 @@ -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); @@ -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 @@ -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