Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3180055imw; Mon, 11 Jul 2022 03:41:40 -0700 (PDT) X-Google-Smtp-Source: AGRyM1to+0AjQFkHnURdo3lqP7iJFPLSAreN1v0z20BnZPxNyBACLWuTxLj62jm7rM9LB300Odx5 X-Received: by 2002:a17:90b:4c48:b0:1ef:ff05:99f5 with SMTP id np8-20020a17090b4c4800b001efff0599f5mr16580175pjb.21.1657536100454; Mon, 11 Jul 2022 03:41:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657536100; cv=none; d=google.com; s=arc-20160816; b=acYPUIRskDWW7AF511pxlExDi0GwffYDecuqf7EsVROl6Z7MuN8+Dz6bizBB0EQiuW 1uJi9zrdF/v20qjuSSXDqvNyEg4N0ReKiPL02adz3MsprZF9/8X3YWTe8siuHM+Pf2Uv gng2gPEn6MHni1RBxNkUy7ruaw6diBW1oXkz8ue2MixmZntazN0xBl+P/KcbgknX6ZDT yjeuWTyj0gmK9sAnf9R8/tRRH1MYWoT8B8hiKtCikItldKYJy9xKDnOyq9dQtuY4p2de rhq4fIsq+YWsawBicZLOeVzUJOQ4L+/+SlM1+focEwISc7NRyx9D10OveNrQlxTdlzxy 7f8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=HbeD/2SfucGGmN6rJq4DeT4PK+xtKx0MZFKVNXh8ijU=; b=dq9KeQc0I0BmVDgPOp8EnxynIYYFtld4lIHKhInF8GCANXgfWEgZ7Wui1hPu2qnyc3 x1hOtszWkBpStLztl1FyT9dLFxdWKghlhjYB79knmwDSJivHJ0rnKexafL5rCbtz4byM ZSMeQFwJjWot7JfZ/Yx5gabp/9Jk8qmVRh6DBBpNQ/k827TGUmnp3nWoy96lcbuJpBE+ N6Qg41LfpbFYLNYKh3cmODgdb9tsuGrSg9+zkHHkvFxD2GD9p03vOrwmPzeJfpCEf+dg r2Kjnddz2mu7wc5UKgbMBNazGBKQ4RnmidADEnmhO3xgGfVSadjQxuglAb75BxtMIXGO 9Hpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Pq8O3yR3; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s21-20020a63dc15000000b00405e570b94dsi10441479pgg.88.2022.07.11.03.41.27; Mon, 11 Jul 2022 03:41:40 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Pq8O3yR3; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232271AbiGKJ0F (ORCPT + 99 others); Mon, 11 Jul 2022 05:26:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232355AbiGKJYd (ORCPT ); Mon, 11 Jul 2022 05:24:33 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B6F1248F7; Mon, 11 Jul 2022 02:14:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 42A6BB80956; Mon, 11 Jul 2022 09:14:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96A62C34115; Mon, 11 Jul 2022 09:14:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657530884; bh=lIq5QL1O+Kc+TdTym8+QkepgY8j0DpxAsVZjsV1n+AI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pq8O3yR3g8KYbWIVBqlqK6bODKqRrpTjBNGM0oei3+cVXUMoPrPhVs6n6KfShC/Ij 0nGpgngf6fDnjw5kUfJZMLYAoc75mNcESpUTnOxbgT7/Oyd0RKqoEYcsd87Ei/xiDK Jp90cm3vrqXLElfEojk7vHUZuyt+n2xc5LYLL98k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Duoming Zhou , Jakub Kicinski Subject: [PATCH 5.18 019/112] net: rose: fix UAF bug caused by rose_t0timer_expiry Date: Mon, 11 Jul 2022 11:06:19 +0200 Message-Id: <20220711090550.104404747@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220711090549.543317027@linuxfoundation.org> References: <20220711090549.543317027@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Duoming Zhou commit 148ca04518070910739dfc4eeda765057856403d upstream. There are UAF bugs caused by rose_t0timer_expiry(). The root cause is that del_timer() could not stop the timer handler that is running and there is no synchronization. One of the race conditions is shown below: (thread 1) | (thread 2) | rose_device_event | rose_rt_device_down | rose_remove_neigh rose_t0timer_expiry | rose_stop_t0timer(rose_neigh) ... | del_timer(&neigh->t0timer) | kfree(rose_neigh) //[1]FREE neigh->dce_mode //[2]USE | The rose_neigh is deallocated in position [1] and use in position [2]. The crash trace triggered by POC is like below: BUG: KASAN: use-after-free in expire_timers+0x144/0x320 Write of size 8 at addr ffff888009b19658 by task swapper/0/0 ... Call Trace: dump_stack_lvl+0xbf/0xee print_address_description+0x7b/0x440 print_report+0x101/0x230 ? expire_timers+0x144/0x320 kasan_report+0xed/0x120 ? expire_timers+0x144/0x320 expire_timers+0x144/0x320 __run_timers+0x3ff/0x4d0 run_timer_softirq+0x41/0x80 __do_softirq+0x233/0x544 ... This patch changes rose_stop_ftimer() and rose_stop_t0timer() in rose_remove_neigh() to del_timer_sync() in order that the timer handler could be finished before the resources such as rose_neigh and so on are deallocated. As a result, the UAF bugs could be mitigated. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Duoming Zhou Link: https://lore.kernel.org/r/20220705125610.77971-1-duoming@zju.edu.cn Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/rose/rose_route.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/net/rose/rose_route.c +++ b/net/rose/rose_route.c @@ -227,8 +227,8 @@ static void rose_remove_neigh(struct ros { struct rose_neigh *s; - rose_stop_ftimer(rose_neigh); - rose_stop_t0timer(rose_neigh); + del_timer_sync(&rose_neigh->ftimer); + del_timer_sync(&rose_neigh->t0timer); skb_queue_purge(&rose_neigh->queue);