Linux-m68k Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] net: dst: Force 4-byte alignment of dst_metrics
@ 2019-12-20 13:31 Geert Uytterhoeven
  2019-12-21  5:54 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Geert Uytterhoeven @ 2019-12-20 13:31 UTC (permalink / raw)
  To: David S . Miller
  Cc: Hannes Frederic Sowa, Michal Kubeček, netdev, linux-kernel,
	linux-m68k, Geert Uytterhoeven

When storing a pointer to a dst_metrics structure in dst_entry._metrics,
two flags are added in the least significant bits of the pointer value.
Hence this assumes all pointers to dst_metrics structures have at least
4-byte alignment.

However, on m68k, the minimum alignment of 32-bit values is 2 bytes, not
4 bytes.  Hence in some kernel builds, dst_default_metrics may be only
2-byte aligned, leading to obscure boot warnings like:

    WARNING: CPU: 0 PID: 7 at lib/refcount.c:28 refcount_warn_saturate+0x44/0x9a
    refcount_t: underflow; use-after-free.
    Modules linked in:
    CPU: 0 PID: 7 Comm: ksoftirqd/0 Tainted: G        W         5.5.0-rc2-atari-01448-g114a1a1038af891d-dirty #261
    Stack from 10835e6c:
	    10835e6c 0038134f 00023fa6 00394b0f 0000001c 00000009 00321560 00023fea
	    00394b0f 0000001c 001a70f8 00000009 00000000 10835eb4 00000001 00000000
	    04208040 0000000a 00394b4a 10835ed4 00043aa8 001a70f8 00394b0f 0000001c
	    00000009 00394b4a 0026aba8 003215a4 00000003 00000000 0026d5a8 00000001
	    003215a4 003a4361 003238d6 000001f0 00000000 003215a4 10aa3b00 00025e84
	    003ddb00 10834000 002416a8 10aa3b00 00000000 00000080 000aa038 0004854a
    Call Trace: [<00023fa6>] __warn+0xb2/0xb4
     [<00023fea>] warn_slowpath_fmt+0x42/0x64
     [<001a70f8>] refcount_warn_saturate+0x44/0x9a
     [<00043aa8>] printk+0x0/0x18
     [<001a70f8>] refcount_warn_saturate+0x44/0x9a
     [<0026aba8>] refcount_sub_and_test.constprop.73+0x38/0x3e
     [<0026d5a8>] ipv4_dst_destroy+0x5e/0x7e
     [<00025e84>] __local_bh_enable_ip+0x0/0x8e
     [<002416a8>] dst_destroy+0x40/0xae

Fix this by forcing 4-byte alignment of all dst_metrics structures.

Fixes: e5fd387ad5b30ca3 ("ipv6: do not overwrite inetpeer metrics prematurely")
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
 include/net/dst.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/net/dst.h b/include/net/dst.h
index fe62fe2eb781c122..8224dad2ae9460fb 100644
--- a/include/net/dst.h
+++ b/include/net/dst.h
@@ -82,7 +82,7 @@ struct dst_entry {
 struct dst_metrics {
 	u32		metrics[RTAX_MAX];
 	refcount_t	refcnt;
-};
+} __aligned(4);		/* Low pointer bits contain DST_METRICS_FLAGS */
 extern const struct dst_metrics dst_default_metrics;
 
 u32 *dst_cow_metrics_generic(struct dst_entry *dst, unsigned long old);
-- 
2.17.1


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

* Re: [PATCH] net: dst: Force 4-byte alignment of dst_metrics
  2019-12-20 13:31 [PATCH] net: dst: Force 4-byte alignment of dst_metrics Geert Uytterhoeven
@ 2019-12-21  5:54 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2019-12-21  5:54 UTC (permalink / raw)
  To: geert; +Cc: hannes, mkubecek, netdev, linux-kernel, linux-m68k

From: Geert Uytterhoeven <geert@linux-m68k.org>
Date: Fri, 20 Dec 2019 14:31:40 +0100

> When storing a pointer to a dst_metrics structure in dst_entry._metrics,
> two flags are added in the least significant bits of the pointer value.
> Hence this assumes all pointers to dst_metrics structures have at least
> 4-byte alignment.
> 
> However, on m68k, the minimum alignment of 32-bit values is 2 bytes, not
> 4 bytes.  Hence in some kernel builds, dst_default_metrics may be only
> 2-byte aligned, leading to obscure boot warnings like:
> 
>     WARNING: CPU: 0 PID: 7 at lib/refcount.c:28 refcount_warn_saturate+0x44/0x9a
>     refcount_t: underflow; use-after-free.
>     Modules linked in:
>     CPU: 0 PID: 7 Comm: ksoftirqd/0 Tainted: G        W         5.5.0-rc2-atari-01448-g114a1a1038af891d-dirty #261
>     Stack from 10835e6c:
> 	    10835e6c 0038134f 00023fa6 00394b0f 0000001c 00000009 00321560 00023fea
> 	    00394b0f 0000001c 001a70f8 00000009 00000000 10835eb4 00000001 00000000
> 	    04208040 0000000a 00394b4a 10835ed4 00043aa8 001a70f8 00394b0f 0000001c
> 	    00000009 00394b4a 0026aba8 003215a4 00000003 00000000 0026d5a8 00000001
> 	    003215a4 003a4361 003238d6 000001f0 00000000 003215a4 10aa3b00 00025e84
> 	    003ddb00 10834000 002416a8 10aa3b00 00000000 00000080 000aa038 0004854a
>     Call Trace: [<00023fa6>] __warn+0xb2/0xb4
>      [<00023fea>] warn_slowpath_fmt+0x42/0x64
>      [<001a70f8>] refcount_warn_saturate+0x44/0x9a
>      [<00043aa8>] printk+0x0/0x18
>      [<001a70f8>] refcount_warn_saturate+0x44/0x9a
>      [<0026aba8>] refcount_sub_and_test.constprop.73+0x38/0x3e
>      [<0026d5a8>] ipv4_dst_destroy+0x5e/0x7e
>      [<00025e84>] __local_bh_enable_ip+0x0/0x8e
>      [<002416a8>] dst_destroy+0x40/0xae
> 
> Fix this by forcing 4-byte alignment of all dst_metrics structures.
> 
> Fixes: e5fd387ad5b30ca3 ("ipv6: do not overwrite inetpeer metrics prematurely")
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>

Applied.

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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-20 13:31 [PATCH] net: dst: Force 4-byte alignment of dst_metrics Geert Uytterhoeven
2019-12-21  5:54 ` David Miller

Linux-m68k Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-m68k/0 linux-m68k/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 linux-m68k linux-m68k/ https://lore.kernel.org/linux-m68k \
		linux-m68k@vger.kernel.org linux-m68k@lists.linux-m68k.org
	public-inbox-index linux-m68k

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-m68k


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