From: Paul Moore <paul@paul-moore.com>
To: Aleksandr Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
Cc: davem@davemloft.net, linux-kernel@vger.kernel.org,
netdev@vger.kernel.org, Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Leon Romanovsky <leon@kernel.org>,
jmorris@namei.org, serge@hallyn.com,
linux-security-module@vger.kernel.org, selinux@vger.kernel.org
Subject: Re: [PATCH net-next v2] scm: fix MSG_CTRUNC setting condition for SO_PASSSEC
Date: Mon, 13 Mar 2023 16:43:35 -0400 [thread overview]
Message-ID: <CAHC9VhT2-QJ6yRoAvbicg5n_NUZLpJ5YjNer4TcHwiaW2hq6FQ@mail.gmail.com> (raw)
In-Reply-To: <CAEivzxf630y_kjVLNM4m1vfQxnwyOBK+0wiCLW1T+8miPVC5Fg@mail.gmail.com>
On Mon, Mar 13, 2023 at 7:40 AM Aleksandr Mikhalitsyn
<aleksandr.mikhalitsyn@canonical.com> wrote:
>
> +CC security subsystem folks
>
> On Mon, Mar 13, 2023 at 12:32 PM Alexander Mikhalitsyn
> <aleksandr.mikhalitsyn@canonical.com> wrote:
> >
> > Currently, kernel would set MSG_CTRUNC flag if msg_control buffer
> > wasn't provided and SO_PASSCRED was set or if there was pending SCM_RIGHTS.
> >
> > For some reason we have no corresponding check for SO_PASSSEC.
> >
> > In the recvmsg(2) doc we have:
> > MSG_CTRUNC
> > indicates that some control data was discarded due to lack
> > of space in the buffer for ancillary data.
> >
> > So, we need to set MSG_CTRUNC flag for all types of SCM.
> >
> > This change can break applications those don't check MSG_CTRUNC flag.
Unless I'm missing something I don't think this will actually result
in a userspace visible change as put_cmsg() already has a number of
checks which set the MSG_CTRUNC flag if necessary (including if no
control buffer is passed, e.g. msg_control == NULL).
Regardless, it looks fine to me.
Acked-by: Paul Moore <paul@paul-moore.com>
> > Cc: "David S. Miller" <davem@davemloft.net>
> > Cc: Eric Dumazet <edumazet@google.com>
> > Cc: Jakub Kicinski <kuba@kernel.org>
> > Cc: Paolo Abeni <pabeni@redhat.com>
> > Cc: Leon Romanovsky <leon@kernel.org>
> > Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> > Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
> >
> > v2:
> > - commit message was rewritten according to Eric's suggestion
> > ---
> > include/net/scm.h | 13 ++++++++++++-
> > 1 file changed, 12 insertions(+), 1 deletion(-)
> >
> > diff --git a/include/net/scm.h b/include/net/scm.h
> > index 1ce365f4c256..585adc1346bd 100644
> > --- a/include/net/scm.h
> > +++ b/include/net/scm.h
> > @@ -105,16 +105,27 @@ static inline void scm_passec(struct socket *sock, struct msghdr *msg, struct sc
> > }
> > }
> > }
> > +
> > +static inline bool scm_has_secdata(struct socket *sock)
> > +{
> > + return test_bit(SOCK_PASSSEC, &sock->flags);
> > +}
> > #else
> > static inline void scm_passec(struct socket *sock, struct msghdr *msg, struct scm_cookie *scm)
> > { }
> > +
> > +static inline bool scm_has_secdata(struct socket *sock)
> > +{
> > + return false;
> > +}
> > #endif /* CONFIG_SECURITY_NETWORK */
> >
> > static __inline__ void scm_recv(struct socket *sock, struct msghdr *msg,
> > struct scm_cookie *scm, int flags)
> > {
> > if (!msg->msg_control) {
> > - if (test_bit(SOCK_PASSCRED, &sock->flags) || scm->fp)
> > + if (test_bit(SOCK_PASSCRED, &sock->flags) || scm->fp ||
> > + scm_has_secdata(sock))
> > msg->msg_flags |= MSG_CTRUNC;
> > scm_destroy(scm);
> > return;
> > --
> > 2.34.1
--
paul-moore.com
next parent reply other threads:[~2023-03-13 20:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20230313113211.178010-1-aleksandr.mikhalitsyn@canonical.com>
[not found] ` <CAEivzxf630y_kjVLNM4m1vfQxnwyOBK+0wiCLW1T+8miPVC5Fg@mail.gmail.com>
2023-03-13 20:43 ` Paul Moore [this message]
2023-03-14 11:06 ` [PATCH net-next v2] scm: fix MSG_CTRUNC setting condition for SO_PASSSEC Aleksandr Mikhalitsyn
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=CAHC9VhT2-QJ6yRoAvbicg5n_NUZLpJ5YjNer4TcHwiaW2hq6FQ@mail.gmail.com \
--to=paul@paul-moore.com \
--cc=aleksandr.mikhalitsyn@canonical.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jmorris@namei.org \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=selinux@vger.kernel.org \
--cc=serge@hallyn.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).