netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] CIPSO: Fix unaligned memory access in cipso_v4_gentag_hdr
@ 2021-03-05  8:05 Sergey Nazarov
  2021-03-05 16:42 ` Paul Moore
  0 siblings, 1 reply; 2+ messages in thread
From: Sergey Nazarov @ 2021-03-05  8:05 UTC (permalink / raw)
  To: linux-security-module; +Cc: paul, davem, netdev, Ondrej Mosnacek

We need to use put_unaligned when writing 32-bit DOI value
in cipso_v4_gentag_hdr to avoid unaligned memory access.

v2: unneeded type cast removed as Ondrej Mosnacek suggested.

Signed-off-by: Sergey Nazarov <s-nazarov@yandex.ru>
---
 net/ipv4/cipso_ipv4.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv4/cipso_ipv4.c b/net/ipv4/cipso_ipv4.c
index 471d33a..6e59902 100644
--- a/net/ipv4/cipso_ipv4.c
+++ b/net/ipv4/cipso_ipv4.c
@@ -1162,7 +1162,7 @@ static void cipso_v4_gentag_hdr(const struct
cipso_v4_doi *doi_def,
 {
 	buf[0] = IPOPT_CIPSO;
 	buf[1] = CIPSO_V4_HDR_LEN + len;
-	*(__be32 *)&buf[2] = htonl(doi_def->doi);
+	put_unaligned_be32(doi_def->doi, &buf[2]);
 }
 
 /**
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] CIPSO: Fix unaligned memory access in cipso_v4_gentag_hdr
  2021-03-05  8:05 [PATCH v2] CIPSO: Fix unaligned memory access in cipso_v4_gentag_hdr Sergey Nazarov
@ 2021-03-05 16:42 ` Paul Moore
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Moore @ 2021-03-05 16:42 UTC (permalink / raw)
  To: Sergey Nazarov; +Cc: linux-security-module, davem, netdev, Ondrej Mosnacek

On Fri, Mar 5, 2021 at 3:05 AM Sergey Nazarov <s-nazarov@yandex.ru> wrote:
>
> We need to use put_unaligned when writing 32-bit DOI value
> in cipso_v4_gentag_hdr to avoid unaligned memory access.
>
> v2: unneeded type cast removed as Ondrej Mosnacek suggested.
>
> Signed-off-by: Sergey Nazarov <s-nazarov@yandex.ru>
> ---
>  net/ipv4/cipso_ipv4.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Acked-by: Paul Moore <paul@paul-moore.com>

> diff --git a/net/ipv4/cipso_ipv4.c b/net/ipv4/cipso_ipv4.c
> index 471d33a..6e59902 100644
> --- a/net/ipv4/cipso_ipv4.c
> +++ b/net/ipv4/cipso_ipv4.c
> @@ -1162,7 +1162,7 @@ static void cipso_v4_gentag_hdr(const struct
> cipso_v4_doi *doi_def,
>  {
>         buf[0] = IPOPT_CIPSO;
>         buf[1] = CIPSO_V4_HDR_LEN + len;
> -       *(__be32 *)&buf[2] = htonl(doi_def->doi);
> +       put_unaligned_be32(doi_def->doi, &buf[2]);
>  }
>
>  /**
> --
> 1.8.3.1

-- 
paul moore
www.paul-moore.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-03-05 16:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-05  8:05 [PATCH v2] CIPSO: Fix unaligned memory access in cipso_v4_gentag_hdr Sergey Nazarov
2021-03-05 16:42 ` Paul Moore

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).