* [PATCH v2] smackfs: fix IPv6 netlabel prefix mask for non-16-aligned lengths
@ 2026-11-17 2:11 Hongjian Dai
2026-12-01 22:37 ` Casey Schaufler
0 siblings, 1 reply; 2+ messages in thread
From: Hongjian Dai @ 2026-11-17 2:11 UTC (permalink / raw)
To: casey
Cc: paul, jmorris, serge, linux-security-module, linux-kernel, Hongjian Dai
smk_write_net6addr() builds the partial-word mask as (1 << m) - 1,
which keeps the low m bits instead of the high m bits (e.g. /33
yields 0x0001 instead of 0x8000), and stores it without htons()
while the address words are in network byte order. Any prefix with
mask % 16 != 0 is truncated to the wrong network and mislabeled.
Take the high m bits and convert to network byte order, matching
how newname words are stored with htons().
Fixes: 21abb1ec414c ("Smack: IPv6 host labeling")
Signed-off-by: Hongjian Dai <daihongjian@kylinsec.com.cn>
---
Link: https://lore.kernel.org/linux-security-module/A82C90B4956EE3A9+20260922144738.9594-1-daihongjian@kylinsec.com.cn/
v2: Added missing Signed-off-by tag (as requested by Casey).
---
security/smack/smackfs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c
index a72bc7fabea9..6d680424a8c3 100644
--- a/security/smack/smackfs.c
+++ b/security/smack/smackfs.c
@@ -1506,7 +1506,7 @@ static ssize_t smk_write_net6addr(struct file *file, const char __user *buf,
fullmask.s6_addr16[i] = 0xffff;
m -= 16;
} else if (m > 0) {
- fullmask.s6_addr16[i] = (1 << m) - 1;
+ fullmask.s6_addr16[i] = htons(0xffff << (16 - m));
m = 0;
} else
fullmask.s6_addr16[i] = 0;
--
2.53.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v2] smackfs: fix IPv6 netlabel prefix mask for non-16-aligned lengths
2026-11-17 2:11 [PATCH v2] smackfs: fix IPv6 netlabel prefix mask for non-16-aligned lengths Hongjian Dai
@ 2026-12-01 22:37 ` Casey Schaufler
0 siblings, 0 replies; 2+ messages in thread
From: Casey Schaufler @ 2026-12-01 22:37 UTC (permalink / raw)
To: Hongjian Dai
Cc: paul, jmorris, serge, linux-security-module, linux-kernel,
Casey Schaufler
On 11/16/2026 6:11 PM, Hongjian Dai wrote:
> smk_write_net6addr() builds the partial-word mask as (1 << m) - 1,
> which keeps the low m bits instead of the high m bits (e.g. /33
> yields 0x0001 instead of 0x8000), and stores it without htons()
> while the address words are in network byte order. Any prefix with
> mask % 16 != 0 is truncated to the wrong network and mislabeled.
>
> Take the high m bits and convert to network byte order, matching
> how newname words are stored with htons().
>
> Fixes: 21abb1ec414c ("Smack: IPv6 host labeling")
> Signed-off-by: Hongjian Dai <daihongjian@kylinsec.com.cn>
Applied to smack-next. Thank you.
> ---
> Link: https://lore.kernel.org/linux-security-module/A82C90B4956EE3A9+20260922144738.9594-1-daihongjian@kylinsec.com.cn/
> v2: Added missing Signed-off-by tag (as requested by Casey).
> ---
> security/smack/smackfs.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c
> index a72bc7fabea9..6d680424a8c3 100644
> --- a/security/smack/smackfs.c
> +++ b/security/smack/smackfs.c
> @@ -1506,7 +1506,7 @@ static ssize_t smk_write_net6addr(struct file *file, const char __user *buf,
> fullmask.s6_addr16[i] = 0xffff;
> m -= 16;
> } else if (m > 0) {
> - fullmask.s6_addr16[i] = (1 << m) - 1;
> + fullmask.s6_addr16[i] = htons(0xffff << (16 - m));
> m = 0;
> } else
> fullmask.s6_addr16[i] = 0;
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-01 22:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 2:11 [PATCH v2] smackfs: fix IPv6 netlabel prefix mask for non-16-aligned lengths Hongjian Dai
2026-12-01 22:37 ` Casey Schaufler
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®