diff mbox series

[net] neighbour: fix unaligned access to pneigh_entry

Message ID 20230531104233.50645-1-dqfext@gmail.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net] neighbour: fix unaligned access to pneigh_entry | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 2559 this patch: 2559
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 543 this patch: 543
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 2710 this patch: 2710
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 11 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Qingfang Deng May 31, 2023, 10:42 a.m. UTC
From: Qingfang DENG <qingfang.deng@siflower.com.cn>

After the blamed commit, the member key is longer 4-byte aligned. On
platforms that do not support unaligned access, e.g., MIPS32R2 with
unaligned_action set to 2, this will trigger a crash when accessing
an IPv6 pneigh_entry, as the key is cast to an in6_addr pointer.

Align the member to 4 bytes on said platforms.

Fixes: 62dd93181aaa ("[IPV6] NDISC: Set per-entry is_router flag in Proxy NA.")
Signed-off-by: Qingfang DENG <qingfang.deng@siflower.com.cn>
---
 include/net/neighbour.h | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Jakub Kicinski May 31, 2023, 6:16 p.m. UTC | #1
On Wed, 31 May 2023 18:42:33 +0800 Qingfang DENG wrote:
> +#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
>  	u8			key[];
> +#else
> +	u8			key[] __aligned(4);
> +#endif

I'd appreciate a second opinion, but to me it's very unlikely we'd save
any memory even with efficient aligned access here. No reasonably key
will fit into 3 bytes, right? So we can as well avoid the ifdef and
make the key[] always aligned. Or preferably, if it doesn't cause
compilation issues, make the type of the key u32?
Eric Dumazet May 31, 2023, 6:41 p.m. UTC | #2
On Wed, May 31, 2023 at 8:16 PM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Wed, 31 May 2023 18:42:33 +0800 Qingfang DENG wrote:
> > +#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
> >       u8                      key[];
> > +#else
> > +     u8                      key[] __aligned(4);
> > +#endif
>
> I'd appreciate a second opinion, but to me it's very unlikely we'd save
> any memory even with efficient aligned access here. No reasonably key
> will fit into 3 bytes, right? So we can as well avoid the ifdef and
> make the key[] always aligned. Or preferably, if it doesn't cause
> compilation issues, make the type of the key u32?

Same feeling, we could avoid the CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS ifdef.
diff mbox series

Patch

diff --git a/include/net/neighbour.h b/include/net/neighbour.h
index 3fa5774bddac..c0195ed9d111 100644
--- a/include/net/neighbour.h
+++ b/include/net/neighbour.h
@@ -180,7 +180,11 @@  struct pneigh_entry {
 	netdevice_tracker	dev_tracker;
 	u32			flags;
 	u8			protocol;
+#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
 	u8			key[];
+#else
+	u8			key[] __aligned(4);
+#endif
 };
 
 /*