From: Joe Perches <joe@perches.com>
To: David Miller <davem@davemloft.net>
Cc: vladislav.yasevich@hp.com, sri@us.ibm.com,
linux-sctp@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 1/2 v2] sctp: sctp_sendmsg: Don't initialize default_sinfo
Date: Thu, 12 May 2011 14:27:20 -0700 [thread overview]
Message-ID: <1305235641.6124.64.camel@Joe-Laptop> (raw)
In-Reply-To: <20110512.170603.549349521517995900.davem@davemloft.net>
This variable only needs initialization when cmsgs.info
is NULL.
Use memset to ensure padding is also zeroed so
kernel doesn't leak any data.
Signed-off-by: Joe Perches <joe@perches.com>
---
On Thu, 2011-05-12 at 17:06 -0400, David Miller wrote:
From: Joe Perches <joe@perches.com>
> Date: Thu, 12 May 2011 12:19:09 -0700
> > This variable only needs initialization when cmsgs.info
> > is NULL.
> > Don't use memset, just initialize every struct member.
> > Signed-off-by: Joe Perches <joe@perches.com>
> I don't think you do this, this structure has padding holes on pretty
> much every architecture.
> It starts with 3 u16's, then there is a u32, so there is a 2-byte
> piece of padding after the 3rd u16.
> Can you prove that these uninitialized portions never make it to
> userspace? If you can, that proof belongs in the commit message.
Thanks David. I didn't notice it went to userspace.
> I think it's too risky.
It is. I like memset.
The current initialization isn't guaranteed by c90 standard
to zero all padding either. In practice it does though.
The idea was to avoid doing a (non-memset) struct foo bar = {}
when unnecessary for every packet as it's only needed when
cmsgs.info is NULL.
net/sctp/socket.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 33d9ee6..d4b8db1 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -1496,7 +1496,7 @@ SCTP_STATIC int sctp_sendmsg(struct kiocb *iocb, struct sock *sk,
struct sctp_chunk *chunk;
union sctp_addr to;
struct sockaddr *msg_name = NULL;
- struct sctp_sndrcvinfo default_sinfo = { 0 };
+ struct sctp_sndrcvinfo default_sinfo;
struct sctp_sndrcvinfo *sinfo;
struct sctp_initmsg *sinit;
sctp_assoc_t associd = 0;
@@ -1760,6 +1760,7 @@ SCTP_STATIC int sctp_sendmsg(struct kiocb *iocb, struct sock *sk,
/* If the user didn't specify SNDRCVINFO, make up one with
* some defaults.
*/
+ memset(&default_sinfo, 0, sizeof(default_sinfo));
default_sinfo.sinfo_stream = asoc->default_stream;
default_sinfo.sinfo_flags = asoc->default_flags;
default_sinfo.sinfo_ppid = asoc->default_ppid;
next prev parent reply other threads:[~2011-05-12 21:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-12 19:19 [PATCH 0/2] sctp: socket cleanups Joe Perches
2011-05-12 19:19 ` [PATCH 1/2] sctp: sctp_sendmsg: Don't initialize default_sinfo Joe Perches
2011-05-12 21:06 ` David Miller
2011-05-12 21:27 ` Joe Perches [this message]
2011-05-12 21:31 ` [PATCH 1/2 v2] " David Miller
2011-05-12 19:19 ` [PATCH 2/2] sctp: sctp_sendmsg: Don't test known non-null sinfo Joe Perches
2011-05-12 21:31 ` David Miller
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=1305235641.6124.64.camel@Joe-Laptop \
--to=joe@perches.com \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sctp@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=sri@us.ibm.com \
--cc=vladislav.yasevich@hp.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