[PATCH v2] CIPSO: Fix unaligned memory access in cipso_v4_gentag_hdr

Subsystems: networking [general], networking [labeled] (netlabel, labeled ipsec, secmark), the rest

STALE1985d

2 messages, 2 authors, 2021-03-05 · open the first message on its own page

[PATCH v2] CIPSO: Fix unaligned memory access in cipso_v4_gentag_hdr

From: Sergey Nazarov <hidden>
Date: 2021-03-05 08:07:41

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 <redacted>
---
 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

Re: [PATCH v2] CIPSO: Fix unaligned memory access in cipso_v4_gentag_hdr

From: Paul Moore <paul@paul-moore.com>
Date: 2021-03-05 16:43:31

On Fri, Mar 5, 2021 at 3:05 AM Sergey Nazarov [off-list ref] 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 <redacted>
---
 net/ipv4/cipso_ipv4.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Acked-by: Paul Moore <paul@paul-moore.com>
quoted hunk
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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help