Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp817602imu; Fri, 11 Jan 2019 09:32:51 -0800 (PST) X-Google-Smtp-Source: ALg8bN5nR87KdypOnpJhQi0ijFxKtsD/8NvP0Lx8UOmd+UvCc2LhfA2QGZkSi0ZzPsYzOUt7rN4j X-Received: by 2002:a17:902:9f93:: with SMTP id g19mr15247205plq.195.1547227971195; Fri, 11 Jan 2019 09:32:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547227971; cv=none; d=google.com; s=arc-20160816; b=MnJ/8xe8wwMSN8upKpNDkxY+dGVxTK0fuQpTtoeMILITOkneAYeP/P5ZLSDOD3JRrB AWX4OZnu3z9rG8bsjqSQ4trdwpvRUgY8FIjLS0as2fpMWe1/r7O06areDQ3PPBCzQjHU JYxqxUae5yknazFwesAop8vjspH8yGpHkTT+ek/x+nOk2KkhPh6swDcyfA722QgPNU+0 /KuSylXgivG8OjVNqeUnCYTe99Hg7EREap1eAHN4JfaPxkrMAy6JW0pmgIMwKgqyt/Il s61EmI3C6MfOYhZGuW/3FuBERSgSI02ffKNA4m8DGLw1KziYKfFCDaaRUYw6nM+2AeEM ldUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6sUbf+dVTzXYUPrQnf23KOCm+cZVN8S8q/PrAQwk080=; b=BUnKs5eDjTh5rWmUJFDwFs08lIm1bNVy8Cvkuy8Fwu6d/fb0PPH4H2fHX5vwI/Ubob qmIQ4N1mnrrdYxGTRL61i8J6ct1VmZp36bGm2bs/FFSvH3q4Uyx67e9pjLGVLP11ERoq IRI0QweKTFQ70yp86A3gKprgtr03L22JE1AEsiAMn3seYCNkZx+mHKNshB0OzgV+nA1I EMmshtXLlJBINfXVinyA4E9IcNziElYRFqebKPYeVhNvCvQzxbdU84KUAklcoTKmAmX2 isQnHqUGLzYrD1EWAS0rukp18HBifTXLhAl+pMr5jc8AzZ9hOCTNbLdp0hF6u2y5BC9z 7/lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Qx2ZV/Y9"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x32si9903794pld.316.2019.01.11.09.32.35; Fri, 11 Jan 2019 09:32:51 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Qx2ZV/Y9"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387803AbfAKORH (ORCPT + 99 others); Fri, 11 Jan 2019 09:17:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:33428 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387792AbfAKORF (ORCPT ); Fri, 11 Jan 2019 09:17:05 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A7CCC21783; Fri, 11 Jan 2019 14:17:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547216224; bh=sz6nh7noQJYQ3i1NOrwtQlAM03C/iOgcpVgrEb+aMPc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qx2ZV/Y9uDAmessH4CwF6+5+JOl+Tv15EZGSNpBEOH+o3EPcM1a2E67l96BgHfozH iqaMPMttBJmZAUziVg356gYCjLE7sz8Azo0+2UOrs0BJbwNprwsKIuPmgPejTIUNEk Z4gV8VIraEKIlyzIBffU4MoBjM3t54JpZ9DiK9/E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Cong Wang , "David S. Miller" , syzbot+f621cda8b7e598908efa@syzkaller.appspotmail.com Subject: [PATCH 4.4 21/88] netrom: fix locking in nr_find_socket() Date: Fri, 11 Jan 2019 15:07:50 +0100 Message-Id: <20190111131049.284504602@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190111131045.137499039@linuxfoundation.org> References: <20190111131045.137499039@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Cong Wang [ Upstream commit 7314f5480f3e37e570104dc5e0f28823ef849e72 ] nr_find_socket(), nr_find_peer() and nr_find_listener() lock the sock after finding it in the global list. However, the call path requires BH disabled for the sock lock consistently. Actually the locking is unnecessary at this point, we can just hold the sock refcnt to make sure it is not gone after we unlock the global list, and lock it later only when needed. Reported-and-tested-by: syzbot+f621cda8b7e598908efa@syzkaller.appspotmail.com Signed-off-by: Cong Wang Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/netrom/af_netrom.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) --- a/net/netrom/af_netrom.c +++ b/net/netrom/af_netrom.c @@ -153,7 +153,7 @@ static struct sock *nr_find_listener(ax2 sk_for_each(s, &nr_list) if (!ax25cmp(&nr_sk(s)->source_addr, addr) && s->sk_state == TCP_LISTEN) { - bh_lock_sock(s); + sock_hold(s); goto found; } s = NULL; @@ -174,7 +174,7 @@ static struct sock *nr_find_socket(unsig struct nr_sock *nr = nr_sk(s); if (nr->my_index == index && nr->my_id == id) { - bh_lock_sock(s); + sock_hold(s); goto found; } } @@ -198,7 +198,7 @@ static struct sock *nr_find_peer(unsigne if (nr->your_index == index && nr->your_id == id && !ax25cmp(&nr->dest_addr, dest)) { - bh_lock_sock(s); + sock_hold(s); goto found; } } @@ -224,7 +224,7 @@ static unsigned short nr_find_next_circu if (i != 0 && j != 0) { if ((sk=nr_find_socket(i, j)) == NULL) break; - bh_unlock_sock(sk); + sock_put(sk); } id++; @@ -918,6 +918,7 @@ int nr_rx_frame(struct sk_buff *skb, str } if (sk != NULL) { + bh_lock_sock(sk); skb_reset_transport_header(skb); if (frametype == NR_CONNACK && skb->len == 22) @@ -927,6 +928,7 @@ int nr_rx_frame(struct sk_buff *skb, str ret = nr_process_rx_frame(sk, skb); bh_unlock_sock(sk); + sock_put(sk); return ret; } @@ -958,10 +960,12 @@ int nr_rx_frame(struct sk_buff *skb, str (make = nr_make_new(sk)) == NULL) { nr_transmit_refusal(skb, 0); if (sk) - bh_unlock_sock(sk); + sock_put(sk); return 0; } + bh_lock_sock(sk); + window = skb->data[20]; skb->sk = make; @@ -1014,6 +1018,7 @@ int nr_rx_frame(struct sk_buff *skb, str sk->sk_data_ready(sk); bh_unlock_sock(sk); + sock_put(sk); nr_insert_socket(make);