From: Arvind Sankar <niveditas98@gmail.com>
To: Chris Packham <Chris.Packham@alliedtelesis.co.nz>
Cc: David Miller <davem@davemloft.net>,
"jon.maloy@ericsson.com" <jon.maloy@ericsson.com>,
"ying.xue@windriver.com" <ying.xue@windriver.com>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"tipc-discussion@lists.sourceforge.net"
<tipc-discussion@lists.sourceforge.net>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] tipc: Avoid copying bytes beyond the supplied data
Date: Sun, 5 May 2019 16:56:58 -0400 [thread overview]
Message-ID: <20190505205656.GA27130@rani.riverdale.lan> (raw)
In-Reply-To: <306471ba2dc54014a77b090d2cf6a7c7@svr-chch-ex1.atlnz.lc>
On Sun, May 05, 2019 at 08:20:14PM +0000, Chris Packham wrote:
> On 4/05/19 4:45 PM, David Miller wrote:
> > From: Chris Packham <chris.packham@alliedtelesis.co.nz>
> > Date: Thu, 2 May 2019 15:10:04 +1200
> >
> >> TLV_SET is called with a data pointer and a len parameter that tells us
> >> how many bytes are pointed to by data. When invoking memcpy() we need
> >> to careful to only copy len bytes.
> >>
> >> Previously we would copy TLV_LENGTH(len) bytes which would copy an extra
> >> 4 bytes past the end of the data pointer which newer GCC versions
> >> complain about.
> >>
> >> In file included from test.c:17:
> >> In function 'TLV_SET',
> >> inlined from 'test' at test.c:186:5:
> >> /usr/include/linux/tipc_config.h:317:3:
> >> warning: 'memcpy' forming offset [33, 36] is out of the bounds [0, 32]
> >> of object 'bearer_name' with type 'char[32]' [-Warray-bounds]
> >> memcpy(TLV_DATA(tlv_ptr), data, tlv_len);
> >> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >> test.c: In function 'test':
> >> test.c::161:10: note:
> >> 'bearer_name' declared here
> >> char bearer_name[TIPC_MAX_BEARER_NAME];
> >> ^~~~~~~~~~~
> >>
> >> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
> >
> > But now the pad bytes at the end are uninitialized.
> >
> > The whole idea is that the encapsulating TLV object has to be rounded
> > up in size based upon the given 'len' for the data.
> >
>
> TLV_LENGTH() does not account for any padding bytes due to the
> alignment. TLV_SPACE() does but that wasn't used in the code before my
> change.
>
> Are you suggesting something like this
>
>
> - if (len && data)
> - memcpy(TLV_DATA(tlv_ptr), data, tlv_len);
> + if (len && data) {
> + memcpy(TLV_DATA(tlv_ptr), data, len);
> + memset(TLV_DATA(tlv_ptr) + len, 0, TLV_SPACE(len) -
> TLV_LENGTH(len));
> + }
>
>
For zeroing out the padding, should that be done in TCM_SET in the same
file as well? That one only copies data_len bytes but doesn't zero out
any alignment padding.
next prev parent reply other threads:[~2019-05-05 20:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-02 3:10 Chris Packham
2019-05-04 4:44 ` David Miller
2019-05-05 20:20 ` Chris Packham
2019-05-05 20:56 ` Arvind Sankar [this message]
2019-05-05 21:17 ` Chris Packham
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=20190505205656.GA27130@rani.riverdale.lan \
--to=niveditas98@gmail.com \
--cc=Chris.Packham@alliedtelesis.co.nz \
--cc=davem@davemloft.net \
--cc=jon.maloy@ericsson.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=tipc-discussion@lists.sourceforge.net \
--cc=ying.xue@windriver.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
all inboxes | Powered by JetHome®