Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3675920pxv; Mon, 26 Jul 2021 09:11:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBi7rdFdchcwi2orPeYN4G97cD+34Zi30WWbwZsO66k1ZurFo1XWpjxurO1jVEBHxNeuwP X-Received: by 2002:a17:906:8808:: with SMTP id zh8mr17860249ejb.213.1627315885784; Mon, 26 Jul 2021 09:11:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627315885; cv=none; d=google.com; s=arc-20160816; b=AU8uBUy54U1dFPby13EP8ks15P+qepT3dumtQeM9wjYWY4hN/A38GRZBua+wHpoc6Z pd1TFOiuU+zBVWjyM68EFQVqrIlpE81JBJP/u8BUnETfNWRbx938UR7fRGltELGXIvIy OsUiIeST1FSuJI5DbzjOjCVFs0iuqwo1i0W9KS2ejfC5AtR1WFZ/lxxfoXgkyI6D7OfY /Pm7pNmStkMlTeeHTFcTH9+9seTufgb+N0szMt8PCr1ZXjqaRTu3bCBcghW3Gn9mw2xJ v7QPt/bT0QmajFxyiK5WVHJjkBXxDuO2GrXePahqbSTS44A9W9xizyoiMOUqeO9djG0/ xq6Q== 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=NJIGShrHQqzaNdCslXA7rl0IztNcabXP66qDK3h8HrE=; b=NAXoApRfdakAG2iLpg+WaxFelZKDPOqc6dtIBGuVzjLo23r2vjctwyTdZnBTFVb2pW 4VkZJ6Fd8PZEami7FAeIPQo2sh379B+R6H/H/YxIq/nRGh/MeCxE2PRgpc5wzdj6kAOV TgCC6b66DPWtp3iLhxyOqZqTBzyGg1kdJjCmc6rne3FcL0rEFercLeSldeHPHOog8vWT U4nGIOvjvEk7nxwhg+8fH/c3K17FF+BnuFDfi4JOygkYi2MutPDalimxbkoIhDryqHzO KrfmCZeUMfOec2q2s6yairyLuhqqb6t5dM/Z+oyiR20/50Sdends6MPPUkCqdTJoH/S2 E0iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="SdbCK3R/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w9si334084edx.108.2021.07.26.09.11.00; Mon, 26 Jul 2021 09:11:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="SdbCK3R/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S238096AbhGZPYj (ORCPT + 99 others); Mon, 26 Jul 2021 11:24:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:55708 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237620AbhGZPQJ (ORCPT ); Mon, 26 Jul 2021 11:16:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 96C0660F38; Mon, 26 Jul 2021 15:56:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627314997; bh=2tjdCL3aJ6Hw8vCvKplDi9yUOkQlbeIY10x3DZmK5Wo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SdbCK3R/oTAqR2rTPWTssgcjDmhEaw5CwgInYSmNHsoLSSq0D3Wrezt5FD+35/PXA DMREfXOsAbotz7bA0V1euV37WaKpUiwDX0Z+xIjnosoEs2WoI0yV3sk+Z+BwQ5s+Oh SXNaviYWQV/yc/tY4PtUQF/9VO4a9O+X0ylya3m0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nguyen Dinh Phi , syzbot+10f1194569953b72f1ae@syzkaller.appspotmail.com, "David S. Miller" , Sasha Levin Subject: [PATCH 5.4 047/108] netrom: Decrease sock refcount when sock timers expire Date: Mon, 26 Jul 2021 17:38:48 +0200 Message-Id: <20210726153833.195026335@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726153831.696295003@linuxfoundation.org> References: <20210726153831.696295003@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nguyen Dinh Phi [ Upstream commit 517a16b1a88bdb6b530f48d5d153478b2552d9a8 ] Commit 63346650c1a9 ("netrom: switch to sock timer API") switched to use sock timer API. It replaces mod_timer() by sk_reset_timer(), and del_timer() by sk_stop_timer(). Function sk_reset_timer() will increase the refcount of sock if it is called on an inactive timer, hence, in case the timer expires, we need to decrease the refcount ourselves in the handler, otherwise, the sock refcount will be unbalanced and the sock will never be freed. Signed-off-by: Nguyen Dinh Phi Reported-by: syzbot+10f1194569953b72f1ae@syzkaller.appspotmail.com Fixes: 63346650c1a9 ("netrom: switch to sock timer API") Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/netrom/nr_timer.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/net/netrom/nr_timer.c b/net/netrom/nr_timer.c index 9115f8a7dd45..a8da88db7893 100644 --- a/net/netrom/nr_timer.c +++ b/net/netrom/nr_timer.c @@ -121,11 +121,9 @@ static void nr_heartbeat_expiry(struct timer_list *t) is accepted() it isn't 'dead' so doesn't get removed. */ if (sock_flag(sk, SOCK_DESTROY) || (sk->sk_state == TCP_LISTEN && sock_flag(sk, SOCK_DEAD))) { - sock_hold(sk); bh_unlock_sock(sk); nr_destroy_socket(sk); - sock_put(sk); - return; + goto out; } break; @@ -146,6 +144,8 @@ static void nr_heartbeat_expiry(struct timer_list *t) nr_start_heartbeat(sk); bh_unlock_sock(sk); +out: + sock_put(sk); } static void nr_t2timer_expiry(struct timer_list *t) @@ -159,6 +159,7 @@ static void nr_t2timer_expiry(struct timer_list *t) nr_enquiry_response(sk); } bh_unlock_sock(sk); + sock_put(sk); } static void nr_t4timer_expiry(struct timer_list *t) @@ -169,6 +170,7 @@ static void nr_t4timer_expiry(struct timer_list *t) bh_lock_sock(sk); nr_sk(sk)->condition &= ~NR_COND_PEER_RX_BUSY; bh_unlock_sock(sk); + sock_put(sk); } static void nr_idletimer_expiry(struct timer_list *t) @@ -197,6 +199,7 @@ static void nr_idletimer_expiry(struct timer_list *t) sock_set_flag(sk, SOCK_DEAD); } bh_unlock_sock(sk); + sock_put(sk); } static void nr_t1timer_expiry(struct timer_list *t) @@ -209,8 +212,7 @@ static void nr_t1timer_expiry(struct timer_list *t) case NR_STATE_1: if (nr->n2count == nr->n2) { nr_disconnect(sk, ETIMEDOUT); - bh_unlock_sock(sk); - return; + goto out; } else { nr->n2count++; nr_write_internal(sk, NR_CONNREQ); @@ -220,8 +222,7 @@ static void nr_t1timer_expiry(struct timer_list *t) case NR_STATE_2: if (nr->n2count == nr->n2) { nr_disconnect(sk, ETIMEDOUT); - bh_unlock_sock(sk); - return; + goto out; } else { nr->n2count++; nr_write_internal(sk, NR_DISCREQ); @@ -231,8 +232,7 @@ static void nr_t1timer_expiry(struct timer_list *t) case NR_STATE_3: if (nr->n2count == nr->n2) { nr_disconnect(sk, ETIMEDOUT); - bh_unlock_sock(sk); - return; + goto out; } else { nr->n2count++; nr_requeue_frames(sk); @@ -241,5 +241,7 @@ static void nr_t1timer_expiry(struct timer_list *t) } nr_start_t1timer(sk); +out: bh_unlock_sock(sk); + sock_put(sk); } -- 2.30.2