Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3715335pxv; Mon, 26 Jul 2021 10:05:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzl3kBQ4Z0Ez5HxAnIGAzOdCg4QFCwgzMDn7rOfOYcaQUypX0wT7WusOKPl3mwuQqNvQ8wc X-Received: by 2002:ac8:5ac7:: with SMTP id d7mr15827610qtd.240.1627319110749; Mon, 26 Jul 2021 10:05:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627319110; cv=none; d=google.com; s=arc-20160816; b=Oo6K0wIU1pQWHmzlIKEqXIgBVvzXTSsONqItAAqXsdb1sahwQE2ctWlZ/OTy3vaz4w Dh2WpAkAocU9xaRVHVgsLVadWK2/z/bNZgE33KTw46yszsj6Xs7EEQYB6FOFcwVBLsEY gMrGlAqzFwNCy63Y2k1ktRr4pIWE8Lq0ci64gEwreddro2TNqNvRs+9mXjc1SC0uQCUi YlxsrQetLk3oauzvv2WBWAu9wj1kkcOUa4auqSeW/Vl6WyQE6EuiD7e6dyIWx8v4SXbk P8vRmHOXsfLMkUlJK2fqdCXuDWAEqGfl5Ia2K6roaLF5T9zLQHOoGh3PYPQBR2JCWVFn PxXQ== 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=Hz00F5otWG7oMQPxUBuehWRGQz4pRvfL/E76ShS0tNVD61LHrVyymP7VZzmZsuTafX rZflpdzH7lfQX2nyIqjDipBPBJsOSmEFC4P5A9WMsjGt8GIpi46tbi9kDBxvJM14eMh6 XAVCy9Pohs9n49FJ+AJYd96PuQaBaicSYa0w2AYOl/FBzz9FeHuWwpzy9AyXFf97G0yN Lqgm/ojgFsOC6vR+OXuE+Ww3Vx47BC4vjnckzfp9pVEA0kra4TLg8PUA8EPoScux0bYd 8s3cSpSFV9VDvytfak4+uFxK/x59AzS9m3e3iINCM5GsTZ+8PCtUBhTGouVEp1nftrxQ y3NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WgTnVE9h; 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 i14si265539qvo.145.2021.07.26.10.04.38; Mon, 26 Jul 2021 10:05:10 -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=WgTnVE9h; 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 S238467AbhGZPnK (ORCPT + 99 others); Mon, 26 Jul 2021 11:43:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:39526 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237414AbhGZPYB (ORCPT ); Mon, 26 Jul 2021 11:24:01 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 11E4460F6B; Mon, 26 Jul 2021 16:04:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627315470; bh=2tjdCL3aJ6Hw8vCvKplDi9yUOkQlbeIY10x3DZmK5Wo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WgTnVE9hsoPzV35KKooby9hu8f1hFAqOor1rrrWRCSyr/D/IKgZjJBM59jY5lxCLK ylPAKoiPnpfGHqwCOgDi61RyiVGPREkCKpwmZ4jwQRbxz7u0g7BEy7mow/QqROUQZB WadQRmM9izv/6PUxfCEOoelBY7UEbRPzaRnZqWP4= 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.10 074/167] netrom: Decrease sock refcount when sock timers expire Date: Mon, 26 Jul 2021 17:38:27 +0200 Message-Id: <20210726153841.872623999@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726153839.371771838@linuxfoundation.org> References: <20210726153839.371771838@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