Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3163148imw; Mon, 11 Jul 2022 03:16:32 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sxrepqFcaCF0whhHg9JRqGRI5RMoOfNBuISvyM7K5LVlkk4r/gNCBi/8oTVP3Gg8fLRZRK X-Received: by 2002:a17:906:8a4a:b0:72b:5b23:3065 with SMTP id gx10-20020a1709068a4a00b0072b5b233065mr2983432ejc.557.1657534592386; Mon, 11 Jul 2022 03:16:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657534592; cv=none; d=google.com; s=arc-20160816; b=unH/qS2264O+642qikBxfZfPy6MdAFEosB4AbN5wdF95NHPwhES+EBPX0X5woDz2Du 7IF1Y5FgYGlWCN+zD8zVhK5RIzzpRsTNdYB8VboujrzkbIIf1UbJyi6WO+bsWn78afmy OLOeRKFA4L56UQF68IFTjUY4UWO8sKFD5CUARPBc0Y1e7cc4DCBZHLXx0AJS1dDC76nq agLv6SAPrdSFM9Sw5Jdg09N/MjOM6/1QRpui0SIS9XKBvd2pJJ4F+HdcJkerW6Oa/pJ7 y8vaUUW+tFsrX3KMNEY16elSX3aS4WNIv/yuoUx0qmi6XXPnrh+tgpNw0c9oeiNkHBgO 9z9w== 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=pnZ5kEFXwRL0OFB6iMx9VzNfe4bwZJTv7mRDPb9v/Do=; b=fuDo78s+u8WbBX9yAxutDJC+iDSeRLhUugPwBH3OErAP842k7Vbw7S/rH0xknx+Hbg NEEewnxUTGQE02YcMcoJdRhioOvH94qURrfw4zNKMs6eqH5tVqnZkotgk6P96S/KdQrs Ocy0tYn0Dd6qI7YR4kCDuLJZrXhoNMjfr8M0OzsRePwRgf6GEm2u0tPMXhBPwOXsYXEL hMjsQ/5jgw7zkLMHzU54NIuUz/CA3hbrzMgEWhrg2z/YChGSxcac7GwCZhq5/RQPsUHG wiyUJzSsKqMWEDUQuXuNt1jNJS5idEbJo455lGwpbjVCWZ+Eqw1jhP6XZqXeun3FlSXz p4Ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=k6Z+1T0C; 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 hc43-20020a17090716ab00b0072ae568f4a0si11061128ejc.93.2022.07.11.03.16.07; Mon, 11 Jul 2022 03:16:32 -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=k6Z+1T0C; 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 S230039AbiGKJKF (ORCPT + 99 others); Mon, 11 Jul 2022 05:10:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231137AbiGKJJW (ORCPT ); Mon, 11 Jul 2022 05:09:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 465FD22BF8; Mon, 11 Jul 2022 02:08:08 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 4635F611A5; Mon, 11 Jul 2022 09:08:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 558A8C34115; Mon, 11 Jul 2022 09:08:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657530487; bh=87vGQEQfDaYwPc75I7+wx1o+VbDJU1V1K/ZgNF3NO80=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k6Z+1T0C8JI+y3FktPhMVdg6nYFGuilJn+3hua4Ez+u8CxEvK5+qU6xGDm5sgImto pMI6yknRuqbWx/TvdiOw6mUNznnNaZS6UWwIdsGXQglV12s9mQ0cnKttKIJN45kdfx bdoIcOJm0rj0HB19ci2lzartX+i3hwFzY3yqL2u0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Duoming Zhou , Jakub Kicinski Subject: [PATCH 4.14 06/17] net: rose: fix UAF bug caused by rose_t0timer_expiry Date: Mon, 11 Jul 2022 11:06:31 +0200 Message-Id: <20220711090536.447480515@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220711090536.245939953@linuxfoundation.org> References: <20220711090536.245939953@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 @@ -230,8 +230,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);