Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3180120imw; Mon, 11 Jul 2022 03:41:45 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s55h9VzFQX7sNWjoWIOkLF1IMSuo5w7v/nhCQPaNUkt1m6bLXf2OqifzTvvhTpTHsFLKYm X-Received: by 2002:a17:902:a613:b0:168:a216:f3ff with SMTP id u19-20020a170902a61300b00168a216f3ffmr17749109plq.21.1657536105043; Mon, 11 Jul 2022 03:41:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657536105; cv=none; d=google.com; s=arc-20160816; b=E6E2BNeSxNX3ecktTYhi2ZXJ56H4Tq7fizuJoU4LpVWfsxLF3I2cZhcz0/sBYWXKZ+ 5pp6hFlT6YM6OojDXWQ0/B3+M4DqjHMXPPzNR/qZJVKGgcdgPNbC4+QMwhYRXx0NoOgn cbv6MqYcSu+24oLUv05y+0ckw2/w7N7nta7ws7ThSoENHvvY68FStdDQDjxBvVNaPLqh ESnMPAur8PE4GM5nwOZLaNgCt0J8bIEi/CaFg/2gyTCYpWQmGbpBP4K7PZoiHVAXkx3c 77bset0qk7AL1dDXqMai6e2q0CRo4GendiN8SroKKy70RKHxhVyD4khI9n9w9W07dxnC ln5A== 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=E8PXqcy2lwQqJJhAUYurZpE1+6A7D/mcAVBX8Z68hZFDy9V6du3OH2bT1U3LE6RS1f FATTbRPvF5YphAq2Q92Pzn7ILGDE0ih41fBAtTFbvbzUftYbcBf63sUbs0wLB6nSLyC6 7YGe9Nw07Eq+72IMi6It/KQ7DM6NSulBKcO4ywbQVsm4DEqudnql6hzDFVQCvmFjKG15 CBIEp6v5cHiMbKbF5ncAmVcz+PxiyARpuPyjnrzp9tEpkHfMPBqNcLYbO1kwTbKqfNzY kz6K+uI3siGcfuYFnihpqktW6g/ZYkpIzRggm+r8ug4IjVuO5aJpkJxe5uNSYw9MM5kW j56A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OVycGpcc; 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 d10-20020a170902f14a00b0016bbdf2a61fsi7401120plb.274.2022.07.11.03.41.31; Mon, 11 Jul 2022 03:41:45 -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=OVycGpcc; 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 S231710AbiGKJUX (ORCPT + 99 others); Mon, 11 Jul 2022 05:20:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231425AbiGKJTY (ORCPT ); Mon, 11 Jul 2022 05:19:24 -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 EB39051437; Mon, 11 Jul 2022 02:12:17 -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 F266FB80E79; Mon, 11 Jul 2022 09:12:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 60642C34115; Mon, 11 Jul 2022 09:12:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657530734; bh=lIq5QL1O+Kc+TdTym8+QkepgY8j0DpxAsVZjsV1n+AI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OVycGpccJj5CHmFr3RkV8UraM70RDCALQmCa0ToTy/gwbOvM6x81Slurp85K1w7FD vardzfStKgRupJfyW+nDrVPQIG7gWW0tmtUiEHW4zByW4XLYdK35J4N8wMdsiuGsu/ 3gDpuNfK0B4w9/DlFHUcPqr40dZA/NuRnPuHpbes= 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.10 09/55] net: rose: fix UAF bug caused by rose_t0timer_expiry Date: Mon, 11 Jul 2022 11:06:57 +0200 Message-Id: <20220711090542.037058836@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220711090541.764895984@linuxfoundation.org> References: <20220711090541.764895984@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);