Received: by 10.223.185.116 with SMTP id b49csp1051549wrg; Fri, 23 Feb 2018 11:01:58 -0800 (PST) X-Google-Smtp-Source: AH8x226pbZKDDwKHbCVqyFEtRGRBHSVB3npgNlW/QwksCF84gl4p4Xj8IZudk1ifJZvzPWoXx0gI X-Received: by 10.98.74.140 with SMTP id c12mr2199678pfj.44.1519412518214; Fri, 23 Feb 2018 11:01:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519412518; cv=none; d=google.com; s=arc-20160816; b=l1Y3hM2TAq9WNjM3sf1sEY+ZIDE6NZBvQTJCuXSaLfDyXMv2zHokcesI+AvAzRkocU j8o03fCLuRkpMu6TNv75sYYQc7VMHL90TOlM8zlJMsP9lrPY2phP2D381h1hWquwcesh 1M5yLKx8DUG6KIHRQgbuZ54Zd4Aom8N/fjWIFrcoD2/aJmR+JL2ajh3d/mWG/wJU5ghf oM9bYbdthtGf8G7jT5XqlABF1vToWMcXaWLX9tJC/yrF1Ij151XMcc064odAJ32slhnp FCCchdq5JbklaBBUXbEMBssozrDe1Z9f4TXYGqvSUUKFkLVQsVFH7r1+nxS5566AuEZs xInw== 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 :arc-authentication-results; bh=T2HD2LrQ0rKcTcyeWv7kU2HacOs3rmltDyO/KSWAoMI=; b=jYgKDugu/rUOJ4aEeU/452oZFqIoCySL5xEv1I2Odj7/N2ft99zPc6cF9riWLAS7nI OEZ06YABJO96RtwT4nd6zGm7KgE4lp4G8gDdp0DQY39j+piYIV2lUfIqtDzphWqgP6f+ n7LMu5mDdatV3JweDsu+lWY8NlPdYzIbN4Cr+U3J7AH1XW5JtCPhcvmG+g8adR8J1X9f SrhG8vW+0r8O+nSCMKIxKYiwSvqC3nqokH18pPpqe+aB00rr3pHV1KLG7MjUu6k2ag0F CFpb0esVM87b8WP+MS9hSV1DDkrSVUakqmbmsqAVLuGB17CsHOZuSi3pWweq8vTwiWji hRlQ== 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 u17si2222918pfm.190.2018.02.23.11.01.41; Fri, 23 Feb 2018 11:01:58 -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; 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 S965754AbeBWS7G (ORCPT + 99 others); Fri, 23 Feb 2018 13:59:06 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:50772 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965742AbeBWS7E (ORCPT ); Fri, 23 Feb 2018 13:59:04 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 11FD711E2; Fri, 23 Feb 2018 18:59:03 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Petr Vandrovec , Paolo Abeni , "David S. Miller" Subject: [PATCH 4.15 28/45] dn_getsockoptdecnet: move nf_{get/set}sockopt outside sock lock Date: Fri, 23 Feb 2018 19:29:07 +0100 Message-Id: <20180223170719.788075661@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170715.197760019@linuxfoundation.org> References: <20180223170715.197760019@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.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Paolo Abeni commit dfec091439bb2acf763497cfc58f2bdfc67c56b7 upstream. After commit 3f34cfae1238 ("netfilter: on sockopt() acquire sock lock only in the required scope"), the caller of nf_{get/set}sockopt() must not hold any lock, but, in such changeset, I forgot to cope with DECnet. This commit addresses the issue moving the nf call outside the lock, in the dn_{get,set}sockopt() with the same schema currently used by ipv4 and ipv6. Also moves the unhandled sockopts of the end of the main switch statements, to improve code readability. Reported-by: Petr Vandrovec BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=198791#c2 Fixes: 3f34cfae1238 ("netfilter: on sockopt() acquire sock lock only in the required scope") Signed-off-by: Paolo Abeni Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/decnet/af_decnet.c | 62 ++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 29 deletions(-) --- a/net/decnet/af_decnet.c +++ b/net/decnet/af_decnet.c @@ -1338,6 +1338,12 @@ static int dn_setsockopt(struct socket * lock_sock(sk); err = __dn_setsockopt(sock, level, optname, optval, optlen, 0); release_sock(sk); +#ifdef CONFIG_NETFILTER + /* we need to exclude all possible ENOPROTOOPTs except default case */ + if (err == -ENOPROTOOPT && optname != DSO_LINKINFO && + optname != DSO_STREAM && optname != DSO_SEQPACKET) + err = nf_setsockopt(sk, PF_DECnet, optname, optval, optlen); +#endif return err; } @@ -1445,15 +1451,6 @@ static int __dn_setsockopt(struct socket dn_nsp_send_disc(sk, 0x38, 0, sk->sk_allocation); break; - default: -#ifdef CONFIG_NETFILTER - return nf_setsockopt(sk, PF_DECnet, optname, optval, optlen); -#endif - case DSO_LINKINFO: - case DSO_STREAM: - case DSO_SEQPACKET: - return -ENOPROTOOPT; - case DSO_MAXWINDOW: if (optlen != sizeof(unsigned long)) return -EINVAL; @@ -1501,6 +1498,12 @@ static int __dn_setsockopt(struct socket return -EINVAL; scp->info_loc = u.info; break; + + case DSO_LINKINFO: + case DSO_STREAM: + case DSO_SEQPACKET: + default: + return -ENOPROTOOPT; } return 0; @@ -1514,6 +1517,20 @@ static int dn_getsockopt(struct socket * lock_sock(sk); err = __dn_getsockopt(sock, level, optname, optval, optlen, 0); release_sock(sk); +#ifdef CONFIG_NETFILTER + if (err == -ENOPROTOOPT && optname != DSO_STREAM && + optname != DSO_SEQPACKET && optname != DSO_CONACCEPT && + optname != DSO_CONREJECT) { + int len; + + if (get_user(len, optlen)) + return -EFAULT; + + err = nf_getsockopt(sk, PF_DECnet, optname, optval, &len); + if (err >= 0) + err = put_user(len, optlen); + } +#endif return err; } @@ -1579,26 +1596,6 @@ static int __dn_getsockopt(struct socket r_data = &link; break; - default: -#ifdef CONFIG_NETFILTER - { - int ret, len; - - if (get_user(len, optlen)) - return -EFAULT; - - ret = nf_getsockopt(sk, PF_DECnet, optname, optval, &len); - if (ret >= 0) - ret = put_user(len, optlen); - return ret; - } -#endif - case DSO_STREAM: - case DSO_SEQPACKET: - case DSO_CONACCEPT: - case DSO_CONREJECT: - return -ENOPROTOOPT; - case DSO_MAXWINDOW: if (r_len > sizeof(unsigned long)) r_len = sizeof(unsigned long); @@ -1630,6 +1627,13 @@ static int __dn_getsockopt(struct socket r_len = sizeof(unsigned char); r_data = &scp->info_rem; break; + + case DSO_STREAM: + case DSO_SEQPACKET: + case DSO_CONACCEPT: + case DSO_CONREJECT: + default: + return -ENOPROTOOPT; } if (r_data) {