From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-sn1nam02on0103.outbound.protection.outlook.com ([104.47.36.103]:18791 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1032490AbeCAPgy (ORCPT ); Thu, 1 Mar 2018 10:36:54 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Paolo Abeni , "David S . Miller" , Sasha Levin Subject: [added to the 4.1 stable tree] dn_getsockoptdecnet: move nf_{get/set}sockopt outside sock lock Date: Thu, 1 Mar 2018 15:26:46 +0000 Message-ID: <20180301152116.1486-398-alexander.levin@microsoft.com> References: <20180301152116.1486-1-alexander.levin@microsoft.com> In-Reply-To: <20180301152116.1486-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Paolo Abeni This patch has been added to the 4.1 stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ Upstream commit dfec091439bb2acf763497cfc58f2bdfc67c56b7 ] 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=3D198791#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: Sasha Levin --- net/decnet/af_decnet.c | 62 +++++++++++++++++++++++++++-------------------= ---- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c index 2783c538ec19..e31f0da7537a 100644 --- a/net/decnet/af_decnet.c +++ b/net/decnet/af_decnet.c @@ -1337,6 +1337,12 @@ static int dn_setsockopt(struct socket *sock, int le= vel, int optname, char __use lock_sock(sk); err =3D __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 =3D=3D -ENOPROTOOPT && optname !=3D DSO_LINKINFO && + optname !=3D DSO_STREAM && optname !=3D DSO_SEQPACKET) + err =3D nf_setsockopt(sk, PF_DECnet, optname, optval, optlen); +#endif =20 return err; } @@ -1444,15 +1450,6 @@ static int __dn_setsockopt(struct socket *sock, int = level,int optname, char __us dn_nsp_send_disc(sk, 0x38, 0, sk->sk_allocation); break; =20 - 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 !=3D sizeof(unsigned long)) return -EINVAL; @@ -1500,6 +1497,12 @@ static int __dn_setsockopt(struct socket *sock, int = level,int optname, char __us return -EINVAL; scp->info_loc =3D u.info; break; + + case DSO_LINKINFO: + case DSO_STREAM: + case DSO_SEQPACKET: + default: + return -ENOPROTOOPT; } =20 return 0; @@ -1513,6 +1516,20 @@ static int dn_getsockopt(struct socket *sock, int le= vel, int optname, char __use lock_sock(sk); err =3D __dn_getsockopt(sock, level, optname, optval, optlen, 0); release_sock(sk); +#ifdef CONFIG_NETFILTER + if (err =3D=3D -ENOPROTOOPT && optname !=3D DSO_STREAM && + optname !=3D DSO_SEQPACKET && optname !=3D DSO_CONACCEPT && + optname !=3D DSO_CONREJECT) { + int len; + + if (get_user(len, optlen)) + return -EFAULT; + + err =3D nf_getsockopt(sk, PF_DECnet, optname, optval, &len); + if (err >=3D 0) + err =3D put_user(len, optlen); + } +#endif =20 return err; } @@ -1578,26 +1595,6 @@ static int __dn_getsockopt(struct socket *sock, int = level,int optname, char __us r_data =3D &link; break; =20 - default: -#ifdef CONFIG_NETFILTER - { - int ret, len; - - if (get_user(len, optlen)) - return -EFAULT; - - ret =3D nf_getsockopt(sk, PF_DECnet, optname, optval, &len); - if (ret >=3D 0) - ret =3D 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 =3D sizeof(unsigned long); @@ -1629,6 +1626,13 @@ static int __dn_getsockopt(struct socket *sock, int = level,int optname, char __us r_len =3D sizeof(unsigned char); r_data =3D &scp->info_rem; break; + + case DSO_STREAM: + case DSO_SEQPACKET: + case DSO_CONACCEPT: + case DSO_CONREJECT: + default: + return -ENOPROTOOPT; } =20 if (r_data) { --=20 2.14.1