Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3160329imw; Mon, 11 Jul 2022 03:12:57 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ul/3C9/nexzlUPduLZet5cOB5BfDXdruA+90s8mRYRknDW/gNejDxF9yCB2z0QOwQtzSiA X-Received: by 2002:a17:90b:4f4e:b0:1ef:ab40:b345 with SMTP id pj14-20020a17090b4f4e00b001efab40b345mr17134018pjb.226.1657534377449; Mon, 11 Jul 2022 03:12:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657534377; cv=none; d=google.com; s=arc-20160816; b=dHjy1F6+n9IEBP8+3f7kXVoeZuP6AFT3Y/9h280KQ6gKma0yTz/0rP/IWZoJ2BfU9A IiUhcVWNVti68ij6KR96ABstcBC+jBszRZSKH/wdI19MZN8IG5JTbC0jQrG411uNIaEq nySiP8OQiQN2VrfZPSc1oSfOSUht+whK1yn8xQ/dH/gOnsoZUFjqbOiXmGAuZZu3vR6s pRoin/yIMD0dneSkycrpDhTorNOois3NiYE+xsdBE9VZXmxxZ2FiL43iBFn5dsSevH5s eyc9xOvorRvlM/nWXhkRr+NOczEkGH0jAumJfLo65SGydGG7/0MIbIA3q76kFVEKfyD5 1HbQ== 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=eY/IzcIezf/7/EGOEZ1iKjChA+X9/EhDn8mg3tkViA2mFuJHgsx1YJ3lYoX9NkrkG7 diYr85OcK/KLcTBgAq19IiwiuH9feSZZl8t2nwhVXpX72OY4LX+tpUVu2C+r2PZkswvm tJ6l6klBYIfefb1NaEmVMs4yxQu7A5SWuEJKVaXwmZrQ+iYcM3Op16gGN+OZsXcDDxMP Py68nHDN5DaPaYc3ZDSJMiyL8+QWOqVehdpFDIGv5afjtheIuGLx3372LcfsWT+Mxzuv zAsnESieUKiZ+T2+lDYJKxWYwEVaHyRC4rRDZENEsN4OvPbttUGyHkGNv85eU8GRRwYV nHpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Fc2Ct6P7; 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 ij6-20020a170902ab4600b0016b9cf35991si8072395plb.250.2022.07.11.03.12.45; Mon, 11 Jul 2022 03:12:57 -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=Fc2Ct6P7; 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 S231345AbiGKJLz (ORCPT + 99 others); Mon, 11 Jul 2022 05:11:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231293AbiGKJK7 (ORCPT ); Mon, 11 Jul 2022 05:10:59 -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 1AF3E12099; Mon, 11 Jul 2022 02:08:55 -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 9EDF6B80E7F; Mon, 11 Jul 2022 09:08:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A3DDC34115; Mon, 11 Jul 2022 09:08:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657530533; bh=87vGQEQfDaYwPc75I7+wx1o+VbDJU1V1K/ZgNF3NO80=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fc2Ct6P7bowZWrJ1ZH8JkA6I7MrhOzz+r5TfZRf3NAOsVXQ5A1i4QXcJQh+F78Dn+ wwUGpMwngpYnxHCUarXQnCNB9zRBxGwntRNWeeahxF3wdZaC2PKpKNaKOk/l8hOv18 xUAPWlPyjmYzvzNshYS2cO0FdgvXKMpSHf3F0YJ4= 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.19 07/31] net: rose: fix UAF bug caused by rose_t0timer_expiry Date: Mon, 11 Jul 2022 11:06:46 +0200 Message-Id: <20220711090538.063243242@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220711090537.841305347@linuxfoundation.org> References: <20220711090537.841305347@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);