All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
To: Xin Long <lucien.xin@gmail.com>
Cc: David Laight <David.Laight@aculab.com>,
	network dev <netdev@vger.kernel.org>,
	"linux-sctp@vger.kernel.org" <linux-sctp@vger.kernel.org>,
	Neil Horman <nhorman@tuxdriver.com>,
	"davem@davemloft.net" <davem@davemloft.net>
Subject: Re: [PATCH net-next 5/5] sctp: add spt_pathcpthld in struct sctp_paddrthlds
Date: Wed, 11 Sep 2019 12:56:09 +0000	[thread overview]
Message-ID: <20190911125609.GC3499@localhost.localdomain> (raw)
In-Reply-To: <CADvbK_dqNas+vwP2t3LqWyabNnzRDO=PZPe4p+zE-vQJTnfKpA@mail.gmail.com>

On Wed, Sep 11, 2019 at 05:38:33PM +0800, Xin Long wrote:
> On Wed, Sep 11, 2019 at 5:21 PM Xin Long <lucien.xin@gmail.com> wrote:
> >
> > On Wed, Sep 11, 2019 at 5:03 PM David Laight <David.Laight@aculab.com> wrote:
> > >
> > > From: Xin Long [mailto:lucien.xin@gmail.com]
> > > > Sent: 11 September 2019 09:52
> > > > On Tue, Sep 10, 2019 at 9:19 PM David Laight <David.Laight@aculab.com> wrote:
> > > > >
> > > > > From: Xin Long
> > > > > > Sent: 09 September 2019 08:57
> > > > > > Section 7.2 of rfc7829: "Peer Address Thresholds (SCTP_PEER_ADDR_THLDS)
> > > > > > Socket Option" extends 'struct sctp_paddrthlds' with 'spt_pathcpthld'
> > > > > > added to allow a user to change ps_retrans per sock/asoc/transport, as
> > > > > > other 2 paddrthlds: pf_retrans, pathmaxrxt.
> > > > > >
> > > > > > Note that ps_retrans is not allowed to be greater than pf_retrans.
> > > > > >
> > > > > > Signed-off-by: Xin Long <lucien.xin@gmail.com>
> > > > > > ---
> > > > > >  include/uapi/linux/sctp.h |  1 +
> > > > > >  net/sctp/socket.c         | 10 ++++++++++
> > > > > >  2 files changed, 11 insertions(+)
> > > > > >
> > > > > > diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h
> > > > > > index a15cc28..dfd81e1 100644
> > > > > > --- a/include/uapi/linux/sctp.h
> > > > > > +++ b/include/uapi/linux/sctp.h
> > > > > > @@ -1069,6 +1069,7 @@ struct sctp_paddrthlds {
> > > > > >       struct sockaddr_storage spt_address;
> > > > > >       __u16 spt_pathmaxrxt;
> > > > > >       __u16 spt_pathpfthld;
> > > > > > +     __u16 spt_pathcpthld;
> > > > > >  };
> > > > > >
> > > > > >  /*
> > > > > > diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> > > > > > index 5e2098b..5b9774d 100644
> > > > > > --- a/net/sctp/socket.c
> > > > > > +++ b/net/sctp/socket.c
> > > > > > @@ -3954,6 +3954,9 @@ static int sctp_setsockopt_paddr_thresholds(struct sock *sk,
> > > > >
> > > > > This code does:
> > > > >         if (optlen < sizeof(struct sctp_paddrthlds))
> > > > >                 return -EINVAL;
> > > > here will become:
> > > >
> > > >         if (optlen >= sizeof(struct sctp_paddrthlds)) {
> > > >                 optlen = sizeof(struct sctp_paddrthlds);
> > > >         } else if (optlen >= ALIGN(offsetof(struct sctp_paddrthlds,
> > > >                                             spt_pathcpthld), 4))
> > > >                 optlen = ALIGN(offsetof(struct sctp_paddrthlds,
> > > >                                         spt_pathcpthld), 4);
> > > >                 val.spt_pathcpthld = 0xffff;
> > > >         else {
> > > >                 return -EINVAL;
> > > >         }
> > >
> > > Hmmm...
> > > If the kernel has to default 'val.spt_pathcpthld = 0xffff'
> > > then recompiling an existing application with the new uapi
> > > header is going to lead to very unexpected behaviour.
> > >
> > > The best you can hope for is that the application memset the
> > > structure to zero.
> > > But more likely it is 'random' on-stack data.
> > 0xffff is a value to disable the feature 'Primary Path Switchover'.
> > you're right that user might set it to zero unexpectly with their
> > old application rebuilt.
> >
> > A safer way is to introduce "sysctl net.sctp.ps_retrans", it won't
> > matter if users set spt_pathcpthld properly when they're not aware
> > of this feature, like "sysctl net.sctp.pF_retrans". Looks better?
> Sorry for confusing,  "sysctl net.sctp.ps_retrans" is already there
> (its value is 0xffff by default),
> we just need to do this in sctp_setsockopt_paddr_thresholds():
> 
>         if (copy_from_user(&val, (struct sctp_paddrthlds __user *)optval,
>                            optlen))
>                 return -EFAULT;
> 
>         if (sock_net(sk)->sctp.ps_retrans = 0xffff)
>                 val.spt_pathcpthld = 0xffff;

I'm confused with the snippets, but if I got them right, this is after
dealing with proper len and could leave val.spt_pathcpthld
uninitialized if the application used the old format and sysctl is !0xffff.

> 
>         if (val.spt_pathpfthld > val.spt_pathcpthld)
>                 return -EINVAL;
> 
> >
> > >
> > >         David
> > >
> > > -
> > > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> > > Registration No: 1397386 (Wales)
> 

WARNING: multiple messages have this Message-ID (diff)
From: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
To: Xin Long <lucien.xin@gmail.com>
Cc: David Laight <David.Laight@aculab.com>,
	network dev <netdev@vger.kernel.org>,
	"linux-sctp@vger.kernel.org" <linux-sctp@vger.kernel.org>,
	Neil Horman <nhorman@tuxdriver.com>,
	"davem@davemloft.net" <davem@davemloft.net>
Subject: Re: [PATCH net-next 5/5] sctp: add spt_pathcpthld in struct sctp_paddrthlds
Date: Wed, 11 Sep 2019 09:56:09 -0300	[thread overview]
Message-ID: <20190911125609.GC3499@localhost.localdomain> (raw)
In-Reply-To: <CADvbK_dqNas+vwP2t3LqWyabNnzRDO=PZPe4p+zE-vQJTnfKpA@mail.gmail.com>

On Wed, Sep 11, 2019 at 05:38:33PM +0800, Xin Long wrote:
> On Wed, Sep 11, 2019 at 5:21 PM Xin Long <lucien.xin@gmail.com> wrote:
> >
> > On Wed, Sep 11, 2019 at 5:03 PM David Laight <David.Laight@aculab.com> wrote:
> > >
> > > From: Xin Long [mailto:lucien.xin@gmail.com]
> > > > Sent: 11 September 2019 09:52
> > > > On Tue, Sep 10, 2019 at 9:19 PM David Laight <David.Laight@aculab.com> wrote:
> > > > >
> > > > > From: Xin Long
> > > > > > Sent: 09 September 2019 08:57
> > > > > > Section 7.2 of rfc7829: "Peer Address Thresholds (SCTP_PEER_ADDR_THLDS)
> > > > > > Socket Option" extends 'struct sctp_paddrthlds' with 'spt_pathcpthld'
> > > > > > added to allow a user to change ps_retrans per sock/asoc/transport, as
> > > > > > other 2 paddrthlds: pf_retrans, pathmaxrxt.
> > > > > >
> > > > > > Note that ps_retrans is not allowed to be greater than pf_retrans.
> > > > > >
> > > > > > Signed-off-by: Xin Long <lucien.xin@gmail.com>
> > > > > > ---
> > > > > >  include/uapi/linux/sctp.h |  1 +
> > > > > >  net/sctp/socket.c         | 10 ++++++++++
> > > > > >  2 files changed, 11 insertions(+)
> > > > > >
> > > > > > diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h
> > > > > > index a15cc28..dfd81e1 100644
> > > > > > --- a/include/uapi/linux/sctp.h
> > > > > > +++ b/include/uapi/linux/sctp.h
> > > > > > @@ -1069,6 +1069,7 @@ struct sctp_paddrthlds {
> > > > > >       struct sockaddr_storage spt_address;
> > > > > >       __u16 spt_pathmaxrxt;
> > > > > >       __u16 spt_pathpfthld;
> > > > > > +     __u16 spt_pathcpthld;
> > > > > >  };
> > > > > >
> > > > > >  /*
> > > > > > diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> > > > > > index 5e2098b..5b9774d 100644
> > > > > > --- a/net/sctp/socket.c
> > > > > > +++ b/net/sctp/socket.c
> > > > > > @@ -3954,6 +3954,9 @@ static int sctp_setsockopt_paddr_thresholds(struct sock *sk,
> > > > >
> > > > > This code does:
> > > > >         if (optlen < sizeof(struct sctp_paddrthlds))
> > > > >                 return -EINVAL;
> > > > here will become:
> > > >
> > > >         if (optlen >= sizeof(struct sctp_paddrthlds)) {
> > > >                 optlen = sizeof(struct sctp_paddrthlds);
> > > >         } else if (optlen >= ALIGN(offsetof(struct sctp_paddrthlds,
> > > >                                             spt_pathcpthld), 4))
> > > >                 optlen = ALIGN(offsetof(struct sctp_paddrthlds,
> > > >                                         spt_pathcpthld), 4);
> > > >                 val.spt_pathcpthld = 0xffff;
> > > >         else {
> > > >                 return -EINVAL;
> > > >         }
> > >
> > > Hmmm...
> > > If the kernel has to default 'val.spt_pathcpthld = 0xffff'
> > > then recompiling an existing application with the new uapi
> > > header is going to lead to very unexpected behaviour.
> > >
> > > The best you can hope for is that the application memset the
> > > structure to zero.
> > > But more likely it is 'random' on-stack data.
> > 0xffff is a value to disable the feature 'Primary Path Switchover'.
> > you're right that user might set it to zero unexpectly with their
> > old application rebuilt.
> >
> > A safer way is to introduce "sysctl net.sctp.ps_retrans", it won't
> > matter if users set spt_pathcpthld properly when they're not aware
> > of this feature, like "sysctl net.sctp.pF_retrans". Looks better?
> Sorry for confusing,  "sysctl net.sctp.ps_retrans" is already there
> (its value is 0xffff by default),
> we just need to do this in sctp_setsockopt_paddr_thresholds():
> 
>         if (copy_from_user(&val, (struct sctp_paddrthlds __user *)optval,
>                            optlen))
>                 return -EFAULT;
> 
>         if (sock_net(sk)->sctp.ps_retrans == 0xffff)
>                 val.spt_pathcpthld = 0xffff;

I'm confused with the snippets, but if I got them right, this is after
dealing with proper len and could leave val.spt_pathcpthld
uninitialized if the application used the old format and sysctl is !=
0xffff.

> 
>         if (val.spt_pathpfthld > val.spt_pathcpthld)
>                 return -EINVAL;
> 
> >
> > >
> > >         David
> > >
> > > -
> > > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> > > Registration No: 1397386 (Wales)
> 

  reply	other threads:[~2019-09-11 12:56 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-09  7:56 [PATCH net-next 0/5] sctp: update from rfc7829 Xin Long
2019-09-09  7:56 ` Xin Long
2019-09-09  7:56 ` [PATCH net-next 1/5] sctp: add SCTP_ADDR_POTENTIALLY_FAILED notification Xin Long
2019-09-09  7:56   ` Xin Long
2019-09-09  7:56   ` [PATCH net-next 2/5] sctp: add pf_expose per netns and sock and asoc Xin Long
2019-09-09  7:56     ` Xin Long
2019-09-09  7:56     ` [PATCH net-next 3/5] sctp: add SCTP_EXPOSE_POTENTIALLY_FAILED_STATE sockopt Xin Long
2019-09-09  7:56       ` Xin Long
2019-09-09  7:56       ` [PATCH net-next 4/5] sctp: add support for Primary Path Switchover Xin Long
2019-09-09  7:56         ` Xin Long
2019-09-09  7:56         ` [PATCH net-next 5/5] sctp: add spt_pathcpthld in struct sctp_paddrthlds Xin Long
2019-09-09  7:56           ` Xin Long
2019-09-10 13:19           ` David Laight
2019-09-11  8:51             ` Xin Long
2019-09-11  8:51               ` Xin Long
2019-09-11  9:03               ` David Laight
2019-09-11  9:03                 ` David Laight
2019-09-11  9:21                 ` Xin Long
2019-09-11  9:21                   ` Xin Long
2019-09-11  9:38                   ` Xin Long
2019-09-11  9:38                     ` Xin Long
2019-09-11 12:56                     ` Marcelo Ricardo Leitner [this message]
2019-09-11 12:56                       ` Marcelo Ricardo Leitner
2019-09-11 17:47                       ` Xin Long
2019-09-11 17:47                         ` Xin Long
2019-09-12 22:51                         ` Marcelo Ricardo Leitner
2019-09-12 22:51                           ` Marcelo Ricardo Leitner
2019-09-13  8:36                           ` David Laight
2019-09-13 13:19                             ` 'Marcelo Ricardo Leitner'
2019-09-13 13:19                               ` 'Marcelo Ricardo Leitner'
2019-09-13 13:31                               ` David Laight
2019-09-13 13:40                                 ` 'Marcelo Ricardo Leitner'
2019-09-13 13:40                                   ` 'Marcelo Ricardo Leitner'
2019-09-10 17:27           ` David Miller
2019-09-10 17:27             ` David Miller
2019-09-11  8:14             ` Xin Long
2019-09-11  8:14               ` Xin Long

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190911125609.GC3499@localhost.localdomain \
    --to=marcelo.leitner@gmail.com \
    --cc=David.Laight@aculab.com \
    --cc=davem@davemloft.net \
    --cc=linux-sctp@vger.kernel.org \
    --cc=lucien.xin@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=nhorman@tuxdriver.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.