Received: by 2002:a05:7412:f584:b0:e2:908c:2ebd with SMTP id eh4csp3313129rdb; Thu, 7 Sep 2023 10:42:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHlrqhOGdPOqY4IPj3us9M9mWW/bDrZGisjX3F0FdclvZhwNb4oBEkiPdxlBiMuFkkMFmsS X-Received: by 2002:ac2:5467:0:b0:500:7c56:ff5 with SMTP id e7-20020ac25467000000b005007c560ff5mr177707lfn.0.1694108543095; Thu, 07 Sep 2023 10:42:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694108543; cv=none; d=google.com; s=arc-20160816; b=PMfSX+mOfeSX8Ylxgk0TZ+eHZd9MkN0ndDqdOgh8ZVPQZpTbPN1Ovv6K/YrCD3XqfQ aOZciGzIzXgZHKwXzxD/LHtDmePGMV9LT7FkTOw/pjAUS9QaZuz8gUOCXoh2x7ZtrZls EAtcdk1iBvhQeD2k/fNsLrZRsJ8PIA841MUO43HlEjTM0zl8X0TaDLJRKH8vkF2no/Ee 0GZJ9rWItsQQJ2r/50/N+uRuauWFSz9b4PXuHVSWC7njBwAVXy06KJtwTT4PwJ5S1Xzd ea6kXNzS0v31teVsbE0wlkYf2MkoUKlGJn7d/eqsX7Y/ixez6kUPKxvEUMt3j4copQeF dW2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=zbF/4CdYNVIpD1H3dtbsa5TOYIWXwK2usFrEJ2pkX30=; fh=dkuDWWqIIhtrmxxm+116HYGzB3CxwAxkV1FC3cDOE1s=; b=0jGTzeIwp5JcGtnhmoKsHJdFOKwZoNYg/8wPwau0yaUyJUAYxpjQREYM84LzThzzbd 3Llre3FzHuFOGGKi14/rQSJudk3CnU1yERI/k6SvQZgUqILE6nR5/Cnwk3bdxogBgbmv qxb+fRtsoarIiu4cA7wunYVB6pJYNsbURcbDxC8oA9FX5Yhe9LyRnlUmKmFqqU5R4Atk MT8dCF/VV2LJ4kR70eI+7TKWQl0XIHNFH+alNxwxbIr0URRA0OdbwnaPkPy5qdwtsWUW jKApxy+dwR6T5evIhZFa1cTKqW56rkhW+ahwxesgrhpnEQf9MwNV3wYfUWZygHhom29h R5zA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s10-20020aa7d78a000000b0052a46e12565si55314edq.194.2023.09.07.10.41.52; Thu, 07 Sep 2023 10:42:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237278AbjIGQJA (ORCPT + 99 others); Thu, 7 Sep 2023 12:09:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239466AbjIGQIE (ORCPT ); Thu, 7 Sep 2023 12:08:04 -0400 Received: from a.mx.secunet.com (a.mx.secunet.com [62.96.220.36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFF8646A1; Thu, 7 Sep 2023 09:01:15 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by a.mx.secunet.com (Postfix) with ESMTP id 1FD9920851; Thu, 7 Sep 2023 12:02:42 +0200 (CEST) X-Virus-Scanned: by secunet Received: from a.mx.secunet.com ([127.0.0.1]) by localhost (a.mx.secunet.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id T5jX2-1IB3fK; Thu, 7 Sep 2023 12:02:41 +0200 (CEST) Received: from mailout1.secunet.com (mailout1.secunet.com [62.96.220.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by a.mx.secunet.com (Postfix) with ESMTPS id 5A84A2070D; Thu, 7 Sep 2023 12:02:41 +0200 (CEST) Received: from cas-essen-01.secunet.de (unknown [10.53.40.201]) by mailout1.secunet.com (Postfix) with ESMTP id 4FB3D80004A; Thu, 7 Sep 2023 12:02:41 +0200 (CEST) Received: from mbx-essen-02.secunet.de (10.53.40.198) by cas-essen-01.secunet.de (10.53.40.201) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.32; Thu, 7 Sep 2023 12:02:41 +0200 Received: from gauss2.secunet.de (10.182.7.193) by mbx-essen-02.secunet.de (10.53.40.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.32; Thu, 7 Sep 2023 12:02:40 +0200 Received: by gauss2.secunet.de (Postfix, from userid 1000) id 8D2D23182AA7; Thu, 7 Sep 2023 12:02:40 +0200 (CEST) Date: Thu, 7 Sep 2023 12:02:40 +0200 From: Steffen Klassert To: Dong Chenchen CC: , , , , , , , , , , , Subject: Re: [Patch net v3] net: xfrm: skip policies marked as dead while reinserting policies Message-ID: References: <20230815141834.1040646-1-dongchenchen2@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20230815141834.1040646-1-dongchenchen2@huawei.com> X-ClientProxiedBy: cas-essen-02.secunet.de (10.53.40.202) To mbx-essen-02.secunet.de (10.53.40.198) X-EXCLAIMER-MD-CONFIG: 2c86f778-e09b-4440-8b15-867914633a10 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 15, 2023 at 10:18:34PM +0800, Dong Chenchen wrote: > BUG: KASAN: slab-use-after-free in xfrm_policy_inexact_list_reinsert+0xb6/0x430 > Read of size 1 at addr ffff8881051f3bf8 by task ip/668 > > CPU: 2 PID: 668 Comm: ip Not tainted 6.5.0-rc5-00182-g25aa0bebba72-dirty #64 > Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.13 04/01/2014 > Call Trace: > > dump_stack_lvl+0x72/0xa0 > print_report+0xd0/0x620 > kasan_report+0xb6/0xf0 > xfrm_policy_inexact_list_reinsert+0xb6/0x430 > xfrm_policy_inexact_insert_node.constprop.0+0x537/0x800 > xfrm_policy_inexact_alloc_chain+0x23f/0x320 > xfrm_policy_inexact_insert+0x6b/0x590 > xfrm_policy_insert+0x3b1/0x480 > xfrm_add_policy+0x23c/0x3c0 > xfrm_user_rcv_msg+0x2d0/0x510 > netlink_rcv_skb+0x10d/0x2d0 > xfrm_netlink_rcv+0x49/0x60 > netlink_unicast+0x3fe/0x540 > netlink_sendmsg+0x528/0x970 > sock_sendmsg+0x14a/0x160 > ____sys_sendmsg+0x4fc/0x580 > ___sys_sendmsg+0xef/0x160 > __sys_sendmsg+0xf7/0x1b0 > do_syscall_64+0x3f/0x90 > entry_SYSCALL_64_after_hwframe+0x73/0xdd > > The root cause is: > > cpu 0 cpu1 > xfrm_dump_policy > xfrm_policy_walk > list_move_tail > xfrm_add_policy > ... ... > xfrm_policy_inexact_list_reinsert > list_for_each_entry_reverse > if (!policy->bydst_reinsert) > //read non-existent policy > xfrm_dump_policy_done > xfrm_policy_walk_done > list_del(&walk->walk.all); > > If dump_one_policy() returns err (triggered by netlink socket), > xfrm_policy_walk() will move walk initialized by socket to list > net->xfrm.policy_all. so this socket becomes visible in the global > policy list. The head *walk can be traversed when users add policies > with different prefixlen and trigger xfrm_policy node merge. > > The issue can also be triggered by policy list traversal while rehashing > and flushing policies. > > It can be fixed by skip such "policies" with walk.dead set to 1. > > Fixes: 9cf545ebd591 ("xfrm: policy: store inexact policies in a tree ordered by destination address") > Fixes: 12a169e7d8f4 ("ipsec: Put dumpers on the dump list") > Signed-off-by: Dong Chenchen Applied, thanks a lot!