mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alexey Khoroshilov <khoroshilov@ispras.ru>
To: Eric Biggers <ebiggers@kernel.org>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
	lvc-project@linuxtesting.org
Subject: Re: [PATCH] crypto: algapi - fix be32_to_cpu macro call in crypto_inc()
Date: Thu, 17 Nov 2022 02:15:42 +0300	[thread overview]
Message-ID: <11f2da35-af59-f0ca-950e-931d6193dc3c@ispras.ru> (raw)
In-Reply-To: <Y3UgUwwV4qZMrzar@sol.localdomain>

On 16.11.2022 20:39, Eric Biggers wrote:
> On Wed, Nov 16, 2022 at 04:52:51PM +0300, Alexey Khoroshilov wrote:
>> be32_to_cpu() macro in some cases may be expanded to an expression
>> that evaluates its arguments multiple times. 
> 
> When is that, exactly?


I considered the path
#define be32_to_cpu __be32_to_cpu

#define __be32_to_cpu(x) __swab32((__force __u32)(__be32)(x))

#define __swab32(x)				\
	(__builtin_constant_p((__u32)(x)) ?	\
	___constant_swab32(x) :			\
	__fswab32(x))


#define ___constant_swab32(x) ((__u32)(				\
	(((__u32)(x) & (__u32)0x000000ffUL) << 24) |		\
	(((__u32)(x) & (__u32)0x0000ff00UL) <<  8) |		\
	(((__u32)(x) & (__u32)0x00ff0000UL) >>  8) |		\
	(((__u32)(x) & (__u32)0xff000000UL) >> 24)))


But you are right, it is protected by __builtin_constant_p() that
prevents that for memory access.


> If that's true, then lots of other places in the kernel would need to be fixed
> too.  Try running:
> 
> 	git grep -E '[bl]e(16|32|64)_to_cpu\([^)]+\+\+\)'
> 
> If true, then it would be much better to fix the macros.


And yes, anyway it makes sense to keep for be32_to_cpu()-like function
macro a contract to handle its arguments as a plain function.

Thanks,
Alexey


      reply	other threads:[~2022-11-16 23:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-16 13:52 Alexey Khoroshilov
2022-11-16 17:39 ` Eric Biggers
2022-11-16 23:15   ` Alexey Khoroshilov [this message]

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=11f2da35-af59-f0ca-950e-931d6193dc3c@ispras.ru \
    --to=khoroshilov@ispras.ru \
    --cc=davem@davemloft.net \
    --cc=ebiggers@kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    /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®