Received: by 10.192.165.148 with SMTP id m20csp767778imm; Fri, 27 Apr 2018 07:13:42 -0700 (PDT) X-Google-Smtp-Source: AB8JxZovQ4miSaLO2bR9GaNZxR8A8z2HbLXSrhUfWb6PHEFQeb3hnWeBMKnAmVwDEVEKI08RKaC7 X-Received: by 2002:a63:41c5:: with SMTP id o188-v6mr2313986pga.280.1524838422923; Fri, 27 Apr 2018 07:13:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524838422; cv=none; d=google.com; s=arc-20160816; b=WTLpE/qTsOO+OhmNDAwNIpF6xqMzGPkTsOj2DWv3SwHDlU4JkSww/PWRxEEzZNJJWR pGln50q7DEnRZYy6ydkx+ZNQnDhlJ1pB4StekG2DFpU10TTE8d4bJwpLQcwflIvm13Tq 7KdZuKPMjsyViu9RuklHVa2S7LdosB2Ms5Olxys0CuNVM5fEH3VMHCP0pq2WTe0LpKhj XLTztRRw4pZr6dxK/HCh0+Lgj00AeNuc3j4q1mvA6g6VjIGz3WSC4crD0JnaLNVCW9Jj QVcv3759erwPR3q//tMvoCOef+u/VkrvUuRm0vwQ6eEOxVXrEfJuzlEsmxx/KYMfG6kW 4U0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dmarc-filter :arc-authentication-results; bh=M3gyS//mj3SbyUxWd+fBM0GRl1FkgCKWl9giu8jh414=; b=IQAdVH6FRndfr9HHEJCiJFFDwc7IwtoLG8wA6RkeuP/Y0JD7AXQdkOGXMj4ijQ6xXv drkv/RV2+EU671IWv5rppwhqbuxGeiDO/Gvi1RW/tFiqqo5v/FehvbQIUsbC5XmFkseM HolCn5d5V1Rj+kVjpVmcZAuPxyjkOmoCRd5OmlQ0dO0VJLV9dlD4txi1QscvfeAzCicU 0pk5zLrgsPHf7wp6VJ/i7umRVS4oM9MjTKJtLLji0jtenCC8znXQ5CSlhdQWqayfvsoN t0odlkHTICCA0PhWa+E7njXw0fSpQmWmK4GTkfSTW03Gfop0yyA/Ml4cQ1qZUCXUWrO9 LXBQ== ARC-Authentication-Results: i=1; mx.google.com; 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 b73-v6si1301666pga.106.2018.04.27.07.13.28; Fri, 27 Apr 2018 07:13:42 -0700 (PDT) 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; 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 S935001AbeD0OLX (ORCPT + 99 others); Fri, 27 Apr 2018 10:11:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:56168 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934768AbeD0OLT (ORCPT ); Fri, 27 Apr 2018 10:11:19 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 45E0E21892; Fri, 27 Apr 2018 14:11:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 45E0E21892 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, kernel test robot , Cong Wang , "David S. Miller" Subject: [PATCH 4.16 46/81] llc: fix NULL pointer deref for SOCK_ZAPPED Date: Fri, 27 Apr 2018 15:58:48 +0200 Message-Id: <20180427135745.864093520@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180427135743.216853156@linuxfoundation.org> References: <20180427135743.216853156@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Cong Wang [ Upstream commit 3a04ce7130a7e5dad4e78d45d50313747f8c830f ] For SOCK_ZAPPED socket, we don't need to care about llc->sap, so we should just skip these refcount functions in this case. Fixes: f7e43672683b ("llc: hold llc_sap before release_sock()") Reported-by: kernel test robot Signed-off-by: Cong Wang Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/llc/af_llc.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) --- a/net/llc/af_llc.c +++ b/net/llc/af_llc.c @@ -189,7 +189,6 @@ static int llc_ui_release(struct socket { struct sock *sk = sock->sk; struct llc_sock *llc; - struct llc_sap *sap; if (unlikely(sk == NULL)) goto out; @@ -200,15 +199,19 @@ static int llc_ui_release(struct socket llc->laddr.lsap, llc->daddr.lsap); if (!llc_send_disc(sk)) llc_ui_wait_for_disc(sk, sk->sk_rcvtimeo); - sap = llc->sap; - /* Hold this for release_sock(), so that llc_backlog_rcv() could still - * use it. - */ - llc_sap_hold(sap); - if (!sock_flag(sk, SOCK_ZAPPED)) + if (!sock_flag(sk, SOCK_ZAPPED)) { + struct llc_sap *sap = llc->sap; + + /* Hold this for release_sock(), so that llc_backlog_rcv() + * could still use it. + */ + llc_sap_hold(sap); llc_sap_remove_socket(llc->sap, sk); - release_sock(sk); - llc_sap_put(sap); + release_sock(sk); + llc_sap_put(sap); + } else { + release_sock(sk); + } if (llc->dev) dev_put(llc->dev); sock_put(sk);