From: Vlad Yasevich <vyasevich@gmail.com>
To: Neil Horman <nhorman@tuxdriver.com>
Cc: netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net>,
linux-sctp@vger.kernel.org
Subject: Re: [PATCH] sctp: Clean up type-punning in sctp_cmd_t union
Date: Thu, 25 Oct 2012 23:48:16 -0400 [thread overview]
Message-ID: <508A0800.10404@gmail.com> (raw)
In-Reply-To: <20121025235843.GA13809@neilslaptop.think-freely.org>
On 10/25/2012 07:58 PM, Neil Horman wrote:
> On Thu, Oct 25, 2012 at 05:42:15PM -0400, Vlad Yasevich wrote:
>> On 10/25/2012 04:47 PM, Neil Horman wrote:
>>> Lots of points in the sctp_cmd_interpreter function treat the sctp_cmd_t arg as
>>> a void pointer, even though they are written as various other types. Theres no
>>> need for this as doing so just leads to possible type-punning issues that could
>>> cause crashes, and if we remain type-consistent we can actually just remove the
>>> void * member of the union entirely.
>>>
>>> Signed-off-by: Neil Horman <nhorman@tuxdriver.com
>>> CC: Vlad Yasevich <vyasevich@gmail.com>
>>> CC: "David S. Miller" <davem@davemloft.net>
>>> CC: linux-sctp@vger.kernel.org
>>> ---
>>> include/net/sctp/command.h | 7 ++++---
>>> include/net/sctp/ulpqueue.h | 2 +-
>>> net/sctp/sm_sideeffect.c | 45 ++++++++++++++++++++++-----------------------
>>> net/sctp/ulpqueue.c | 3 +--
>>> 4 files changed, 28 insertions(+), 29 deletions(-)
>>>
>>> diff --git a/include/net/sctp/command.h b/include/net/sctp/command.h
>>> index 712b3be..7f1b0f3 100644
>>> --- a/include/net/sctp/command.h
>>> +++ b/include/net/sctp/command.h
>>> @@ -131,7 +131,6 @@ typedef union {
>>> sctp_state_t state;
>>> sctp_event_timeout_t to;
>>> unsigned long zero;
>>> - void *ptr;
>>> struct sctp_chunk *chunk;
>>> struct sctp_association *asoc;
>>> struct sctp_transport *transport;
>>> @@ -154,9 +153,12 @@ typedef union {
>>> * which takes an __s32 and returns a sctp_arg_t containing the
>>> * __s32. So, after foo = SCTP_I32(arg), foo.i32 == arg.
>>> */
>>> +#define SCTP_NULL_BYTE 0xAA
>>> static inline sctp_arg_t SCTP_NULL(void)
>>> {
>>> - sctp_arg_t retval; retval.ptr = NULL; return retval;
>>> + sctp_arg_t retval;
>>> + memset(&retval, SCTP_NULL_BYTE, sizeof(sctp_arg_t));
>>> + return retval;
>>
>> What's this for? Can't we just use retval.zero?
>>
>> -vlad
>>
> My intent was to highlight any users of sctp_arg_t when SCTP_NULL was passed.
> My thinking was that the 0xAA byte patern would be a good indicator. Although,
> admittedly I didn't see the zero argument there. Looking at it though, the zero
> member of the union is effectively unused. Strictly speaking its used for
> initalization of sctp_arg_t, but its done somewhat poorly, since theres no
> guarantee that an unsigned long will be the largest member of that union. Doing
> the memset guarantees the whole instance is set to a predefined value.
>
> I could go either way with this, would you rather we just have SCTP_NULL return
> retval = { .zero = 0}; or would you rather remove the zero initialization from
> SCTP_[NO]FORCE, and SCTP_ARG_CONSTRUCTOR and do the memset. I think the memset
> reduces to a single 64 bit assignment as long as the union doesn't exceed that
> size anyway, and it ensures that you initalize the whole union's storage if it
> does in the future. And if we remove the initialization step (I don't see that
> its needed in the three macros above anyway), then we can remove the zero member
> as well.
>
You need the initialization step, otherwise things might fail (they did
on IA64 a while back). That's why the zero member was added. You can
go with memset if you want, but I was primarily wondering why the 0xAA
pattern was there.
-vlad
> Let me know what you want to do here, and I can respin this.
> Best
> Neil
>
next prev parent reply other threads:[~2012-10-26 3:48 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-25 20:47 [PATCH] sctp: Clean up type-punning in sctp_cmd_t union Neil Horman
2012-10-25 21:42 ` Vlad Yasevich
2012-10-25 23:58 ` Neil Horman
2012-10-26 3:48 ` Vlad Yasevich [this message]
2012-10-26 13:24 ` Neil Horman
2012-10-26 19:12 ` Vlad Yasevich
2012-10-26 20:35 ` Neil Horman
2012-10-26 21:10 ` David Miller
2012-10-27 1:42 ` Neil Horman
2012-10-27 2:16 ` Vlad Yasevich
2012-10-29 15:07 ` David Laight
2012-10-29 18:59 ` Neil Horman
2012-10-29 19:04 ` David Miller
2012-10-26 9:00 ` David Laight
2012-10-26 13:28 ` Neil Horman
2012-10-26 13:41 ` [PATCH v2] " Neil Horman
2012-10-26 19:12 ` Vlad Yasevich
2012-10-29 16:35 ` Neil Horman
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=508A0800.10404@gmail.com \
--to=vyasevich@gmail.com \
--cc=davem@davemloft.net \
--cc=linux-sctp@vger.kernel.org \
--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 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).