Received: by 10.223.185.116 with SMTP id b49csp1142439wrg; Fri, 23 Feb 2018 12:41:46 -0800 (PST) X-Google-Smtp-Source: AH8x225on7ftghHQmEsr+gtONdY4NxuVnhP7oq+7IQzrT1KvSE8eDyTaRGvKkEUQgLL/zPMAoFe/ X-Received: by 10.99.5.197 with SMTP id 188mr2364638pgf.196.1519418505905; Fri, 23 Feb 2018 12:41:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519418505; cv=none; d=google.com; s=arc-20160816; b=QRc+i7jc/FpPQ8E3xI3LAjbcOrfd79ldVFLT3qZuQhdynhWM41gx98GKSgVLu5MKQX tCDjSbH488KvOoxju1YB1c7EbAZUpMOnec77HLn7ZgpXWzw1ILiEOB1jWCCgWSoJL2xw m5Q4duLrSEmtODSg4I28ursguWdnJkamBh190p+Db42pRzwWkzS3/UeFiy+RkfhcG4i0 Fkgxf+6vb8z+D6e+wdUHKjCTOR1cL/h6WYx9qILsmJjFAXk2oZsDsZM/Xd4VZvH0mzPX mxbZLuWcrsqsWSjiz/CK6QLVqabs3XX1NDbuftR03kyZ+MghE5CG0h4DhIyWnmpv4gjb WOmw== 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=2EZf67pwns/+3q38DntVB8DYD8BWEVfa5gPAQd8ItbA=; b=as/doiUCI9zcqXPWFTr4qGlOPNKeS++p5BNx57J38DUMxM7XfI9c7US8xqUA+nYp5t zM2K1z81nnZkA9rGgtHH7Yl/VxENtTFsGOOpQGP22ahONiZH/IXwbI8j+A7U3HWiydPS g2sWYVh/0ZhDPOiERPm00uti0MZScuyNMfhG97MvfW5oE1T6gu7MmYEhT5anvp7iU1UR zr1hmSuhWSaMlxWiatx4rELSMNiRBapbX9DtIlVuC+Azln5nNZ0q1CdV9RXo/SBa+3pt S7bNlQ9rbbStZlIouYH74D9eCX36WRzXjeMtjzga6eKO+KhNJTxfTaD7itiwW85GSo5H 7uXg== 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 w16-v6si2259786plp.87.2018.02.23.12.41.30; Fri, 23 Feb 2018 12:41:45 -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 S1753320AbeBWSdo (ORCPT + 99 others); Fri, 23 Feb 2018 13:33:44 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:36644 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753191AbeBWSdm (ORCPT ); Fri, 23 Feb 2018 13:33:42 -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 8F29F1070; Fri, 23 Feb 2018 18:33:41 +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.4 025/193] dn_getsockoptdecnet: move nf_{get/set}sockopt outside sock lock Date: Fri, 23 Feb 2018 19:24:18 +0100 Message-Id: <20180223170329.992961921@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170325.997716448@linuxfoundation.org> References: <20180223170325.997716448@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.4-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 @@ -1337,6 +1337,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; } @@ -1444,15 +1450,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; @@ -1500,6 +1497,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; @@ -1513,6 +1516,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; } @@ -1578,26 +1595,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); @@ -1629,6 +1626,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) {