diff mbox series

[net-next,1/2] netns: Parse NETNSA_FD and NETNSA_PID as signed integers

Message ID 0f37c946179b082bf1c5e34d2cfdd9223979ea83.1579040200.git.gnault@redhat.com
State Changes Requested
Delegated to: David Miller
Headers show
Series netns: simple cleanups | expand

Commit Message

Guillaume Nault Jan. 14, 2020, 10:25 p.m. UTC
These attributes represent signed values (file descriptors and PIDs).
Make that clear in nla_policy.

Signed-off-by: Guillaume Nault <gnault@redhat.com>
---
 net/core/net_namespace.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Comments

Nicolas Dichtel Jan. 15, 2020, 1:30 p.m. UTC | #1
Le 14/01/2020 à 23:25, Guillaume Nault a écrit :
> These attributes represent signed values (file descriptors and PIDs).
> Make that clear in nla_policy.
> 
> Signed-off-by: Guillaume Nault <gnault@redhat.com>
> ---
>  net/core/net_namespace.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
> index 6412c1fbfcb5..85c565571c1c 100644
> --- a/net/core/net_namespace.c
> +++ b/net/core/net_namespace.c
> @@ -706,8 +706,8 @@ static struct pernet_operations __net_initdata net_ns_ops = {
>  static const struct nla_policy rtnl_net_policy[NETNSA_MAX + 1] = {
>  	[NETNSA_NONE]		= { .type = NLA_UNSPEC },
>  	[NETNSA_NSID]		= { .type = NLA_S32 },
> -	[NETNSA_PID]		= { .type = NLA_U32 },
> -	[NETNSA_FD]		= { .type = NLA_U32 },
> +	[NETNSA_PID]		= { .type = NLA_S32 },
> +	[NETNSA_FD]		= { .type = NLA_S32 },
Please, keep them consistent with IFLA_NET_NS_*:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/core/rtnetlink.c?h=v5.5-rc6#n1793

>  	[NETNSA_TARGET_NSID]	= { .type = NLA_S32 },
>  };
>  
> @@ -731,10 +731,10 @@ static int rtnl_net_newid(struct sk_buff *skb, struct nlmsghdr *nlh,
>  	nsid = nla_get_s32(tb[NETNSA_NSID]);
>  
>  	if (tb[NETNSA_PID]) {
> -		peer = get_net_ns_by_pid(nla_get_u32(tb[NETNSA_PID]));
> +		peer = get_net_ns_by_pid(nla_get_s32(tb[NETNSA_PID]));
Same here:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/core/rtnetlink.c?h=v5.5-rc6#n2115


Thank you,
Nicolas
Guillaume Nault Jan. 15, 2020, 2:55 p.m. UTC | #2
On Wed, Jan 15, 2020 at 02:30:13PM +0100, Nicolas Dichtel wrote:
> Le 14/01/2020 à 23:25, Guillaume Nault a écrit :
> > These attributes represent signed values (file descriptors and PIDs).
> > Make that clear in nla_policy.
> > 
> > Signed-off-by: Guillaume Nault <gnault@redhat.com>
> > ---
> >  net/core/net_namespace.c | 12 ++++++------
> >  1 file changed, 6 insertions(+), 6 deletions(-)
> > 
> > diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
> > index 6412c1fbfcb5..85c565571c1c 100644
> > --- a/net/core/net_namespace.c
> > +++ b/net/core/net_namespace.c
> > @@ -706,8 +706,8 @@ static struct pernet_operations __net_initdata net_ns_ops = {
> >  static const struct nla_policy rtnl_net_policy[NETNSA_MAX + 1] = {
> >  	[NETNSA_NONE]		= { .type = NLA_UNSPEC },
> >  	[NETNSA_NSID]		= { .type = NLA_S32 },
> > -	[NETNSA_PID]		= { .type = NLA_U32 },
> > -	[NETNSA_FD]		= { .type = NLA_U32 },
> > +	[NETNSA_PID]		= { .type = NLA_S32 },
> > +	[NETNSA_FD]		= { .type = NLA_S32 },
> Please, keep them consistent with IFLA_NET_NS_*:
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/core/rtnetlink.c?h=v5.5-rc6#n1793
> 
Oh right! I'll also update rtnetlink.c in v2.
Thanks!
diff mbox series

Patch

diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 6412c1fbfcb5..85c565571c1c 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -706,8 +706,8 @@  static struct pernet_operations __net_initdata net_ns_ops = {
 static const struct nla_policy rtnl_net_policy[NETNSA_MAX + 1] = {
 	[NETNSA_NONE]		= { .type = NLA_UNSPEC },
 	[NETNSA_NSID]		= { .type = NLA_S32 },
-	[NETNSA_PID]		= { .type = NLA_U32 },
-	[NETNSA_FD]		= { .type = NLA_U32 },
+	[NETNSA_PID]		= { .type = NLA_S32 },
+	[NETNSA_FD]		= { .type = NLA_S32 },
 	[NETNSA_TARGET_NSID]	= { .type = NLA_S32 },
 };
 
@@ -731,10 +731,10 @@  static int rtnl_net_newid(struct sk_buff *skb, struct nlmsghdr *nlh,
 	nsid = nla_get_s32(tb[NETNSA_NSID]);
 
 	if (tb[NETNSA_PID]) {
-		peer = get_net_ns_by_pid(nla_get_u32(tb[NETNSA_PID]));
+		peer = get_net_ns_by_pid(nla_get_s32(tb[NETNSA_PID]));
 		nla = tb[NETNSA_PID];
 	} else if (tb[NETNSA_FD]) {
-		peer = get_net_ns_by_fd(nla_get_u32(tb[NETNSA_FD]));
+		peer = get_net_ns_by_fd(nla_get_s32(tb[NETNSA_FD]));
 		nla = tb[NETNSA_FD];
 	} else {
 		NL_SET_ERR_MSG(extack, "Peer netns reference is missing");
@@ -874,10 +874,10 @@  static int rtnl_net_getid(struct sk_buff *skb, struct nlmsghdr *nlh,
 	if (err < 0)
 		return err;
 	if (tb[NETNSA_PID]) {
-		peer = get_net_ns_by_pid(nla_get_u32(tb[NETNSA_PID]));
+		peer = get_net_ns_by_pid(nla_get_s32(tb[NETNSA_PID]));
 		nla = tb[NETNSA_PID];
 	} else if (tb[NETNSA_FD]) {
-		peer = get_net_ns_by_fd(nla_get_u32(tb[NETNSA_FD]));
+		peer = get_net_ns_by_fd(nla_get_s32(tb[NETNSA_FD]));
 		nla = tb[NETNSA_FD];
 	} else if (tb[NETNSA_NSID]) {
 		peer = get_net_ns_by_id(net, nla_get_s32(tb[NETNSA_NSID]));