DPDK patches and discussions
 help / color / mirror / Atom feed
From: Жумабеков Ерден Мирзагулович <E_Zhumabekov@sts.kz>
To: Pawel Wodkowski <pawelx.wodkowski@intel.com>,
	"dev@dpdk.org" <dev@dpdk.org>
Subject: Re: [dpdk-dev] [PATCH] hash: fix breaking strict-aliasing rules
Date: Sat, 21 Mar 2015 06:57:05 +0000
Message-ID: <62B92B5760FBDD49B5059B6820A956CF405B447A@exmailbox1.rgp.local> (raw)
In-Reply-To: <550C16FB.5050808@intel.com>

Hi Pawel,

Oops, thanks for the clue. I have a buffer over-read here leading to undefined behaviour.
The only solution I see here is to declare uint32_t pointer and evaluate it to (uint8_t *) data + data_len - (data_len & 0x07). Ideas are welcome. That would resolve strict-aliasing violation.
_____________________
From: Pawel Wodkowski [pawelx.wodkowski@intel.com]
Sent: Friday, March 20, 2015 18:47
To: Жумабеков Ерден Мирзагулович; dev@dpdk.org
Subject: Re: [dpdk-dev] [PATCH] hash: fix breaking strict-aliasing rules

On 2015-03-18 17:51, Yerden Zhumabekov wrote:

>
> -     switch (7 - (data_len & 0x07)) {
> +     i = 7 - (data_len & 0x07);
> +     switch (i) {
>       case 0:
> -             temp |= (uint64_t) *((const uint8_t *)p64 + 6) << 48;
> -             /* Fallthrough */
>       case 1:
> -             temp |= (uint64_t) *((const uint8_t *)p64 + 5) << 40;
> -             /* Fallthrough */
>       case 2:
> -             temp |= (uint64_t) *((const uint8_t *)p64 + 4) << 32;
> -             temp |= *((const uint32_t *)p64);
> +             temp = odd_8byte_mask[i] & *p64;
>               init_val = rte_hash_crc_8byte(temp, init_val);
>               break;
>       case 3:
> -             init_val = rte_hash_crc_4byte(*(const uint32_t *)p64, init_val);
> -             break;
>       case 4:
> -             temp |= *((const uint8_t *)p64 + 2) << 16;
> -             /* Fallthrough */
>       case 5:
> -             temp |= *((const uint8_t *)p64 + 1) << 8;
> -             /* Fallthrough */
>       case 6:
> -             temp |= *((const uint8_t *)p64);
> +             temp = odd_8byte_mask[i] & *p64;
>               init_val = rte_hash_crc_4byte(temp, init_val);
> -             /* Fallthrough */
>       default:
>               break;
>       }
>

Second thought: is this not an issue here reading 8 bytes by
dereferencing *p64 if there is less bytes in buffer?

--
Pawel

  reply	other threads:[~2015-03-21  6:57 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-18 16:51 Yerden Zhumabekov
2015-03-19 16:25 ` Bruce Richardson
2015-03-19 16:31   ` Bruce Richardson
2015-03-20  3:29     ` Yerden Zhumabekov
2015-03-20 12:41 ` Pawel Wodkowski
2015-03-20 12:47 ` Pawel Wodkowski
2015-03-21  6:57   ` Жумабеков Ерден Мирзагулович [this message]
2015-03-24 13:31 ` [dpdk-dev] [PATCH v2] " Yerden Zhumabekov
2015-03-26 17:47   ` De Lara Guarch, Pablo
2015-03-27  9:26     ` Thomas Monjalon

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=62B92B5760FBDD49B5059B6820A956CF405B447A@exmailbox1.rgp.local \
    --to=e_zhumabekov@sts.kz \
    --cc=dev@dpdk.org \
    --cc=pawelx.wodkowski@intel.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

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git