mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH AUTOSEL 6.2 01/45] xfrm: Zero padding when dumping algos and encap
@ 2023-03-22 19:55 Sasha Levin
  2023-03-22 19:55 ` [PATCH AUTOSEL 6.2 02/45] ASoC: codecs: tx-macro: Fix for KASAN: slab-out-of-bounds Sasha Levin
                   ` (43 more replies)
  0 siblings, 44 replies; 45+ messages in thread
From: Sasha Levin @ 2023-03-22 19:55 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Herbert Xu, syzbot+fa5414772d5c445dac3c, Hyunwoo Kim,
	Sabrina Dubroca, Steffen Klassert, Sasha Levin, davem, edumazet,
	kuba, pabeni, netdev

From: Herbert Xu <herbert@gondor.apana.org.au>

[ Upstream commit 8222d5910dae08213b6d9d4bc9a7f8502855e624 ]

When copying data to user-space we should ensure that only valid
data is copied over.  Padding in structures may be filled with
random (possibly sensitve) data and should never be given directly
to user-space.

This patch fixes the copying of xfrm algorithms and the encap
template in xfrm_user so that padding is zeroed.

Reported-by: syzbot+fa5414772d5c445dac3c@syzkaller.appspotmail.com
Reported-by: Hyunwoo Kim <v4bel@theori.io>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Reviewed-by: Sabrina Dubroca <sd@queasysnail.net>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 net/xfrm/xfrm_user.c | 45 ++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 41 insertions(+), 4 deletions(-)

diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index cf5172d4ce68c..103af2b3e986f 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -1012,7 +1012,9 @@ static int copy_to_user_aead(struct xfrm_algo_aead *aead, struct sk_buff *skb)
 		return -EMSGSIZE;
 
 	ap = nla_data(nla);
-	memcpy(ap, aead, sizeof(*aead));
+	strscpy_pad(ap->alg_name, aead->alg_name, sizeof(ap->alg_name));
+	ap->alg_key_len = aead->alg_key_len;
+	ap->alg_icv_len = aead->alg_icv_len;
 
 	if (redact_secret && aead->alg_key_len)
 		memset(ap->alg_key, 0, (aead->alg_key_len + 7) / 8);
@@ -1032,7 +1034,8 @@ static int copy_to_user_ealg(struct xfrm_algo *ealg, struct sk_buff *skb)
 		return -EMSGSIZE;
 
 	ap = nla_data(nla);
-	memcpy(ap, ealg, sizeof(*ealg));
+	strscpy_pad(ap->alg_name, ealg->alg_name, sizeof(ap->alg_name));
+	ap->alg_key_len = ealg->alg_key_len;
 
 	if (redact_secret && ealg->alg_key_len)
 		memset(ap->alg_key, 0, (ealg->alg_key_len + 7) / 8);
@@ -1043,6 +1046,40 @@ static int copy_to_user_ealg(struct xfrm_algo *ealg, struct sk_buff *skb)
 	return 0;
 }
 
+static int copy_to_user_calg(struct xfrm_algo *calg, struct sk_buff *skb)
+{
+	struct nlattr *nla = nla_reserve(skb, XFRMA_ALG_COMP, sizeof(*calg));
+	struct xfrm_algo *ap;
+
+	if (!nla)
+		return -EMSGSIZE;
+
+	ap = nla_data(nla);
+	strscpy_pad(ap->alg_name, calg->alg_name, sizeof(ap->alg_name));
+	ap->alg_key_len = 0;
+
+	return 0;
+}
+
+static int copy_to_user_encap(struct xfrm_encap_tmpl *ep, struct sk_buff *skb)
+{
+	struct nlattr *nla = nla_reserve(skb, XFRMA_ENCAP, sizeof(*ep));
+	struct xfrm_encap_tmpl *uep;
+
+	if (!nla)
+		return -EMSGSIZE;
+
+	uep = nla_data(nla);
+	memset(uep, 0, sizeof(*uep));
+
+	uep->encap_type = ep->encap_type;
+	uep->encap_sport = ep->encap_sport;
+	uep->encap_dport = ep->encap_dport;
+	uep->encap_oa = ep->encap_oa;
+
+	return 0;
+}
+
 static int xfrm_smark_put(struct sk_buff *skb, struct xfrm_mark *m)
 {
 	int ret = 0;
@@ -1098,12 +1135,12 @@ static int copy_to_user_state_extra(struct xfrm_state *x,
 			goto out;
 	}
 	if (x->calg) {
-		ret = nla_put(skb, XFRMA_ALG_COMP, sizeof(*(x->calg)), x->calg);
+		ret = copy_to_user_calg(x->calg, skb);
 		if (ret)
 			goto out;
 	}
 	if (x->encap) {
-		ret = nla_put(skb, XFRMA_ENCAP, sizeof(*x->encap), x->encap);
+		ret = copy_to_user_encap(x->encap, skb);
 		if (ret)
 			goto out;
 	}
-- 
2.39.2


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

end of thread, other threads:[~2023-03-22 20:04 UTC | newest]

Thread overview: 45+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-22 19:55 [PATCH AUTOSEL 6.2 01/45] xfrm: Zero padding when dumping algos and encap Sasha Levin
2023-03-22 19:55 ` [PATCH AUTOSEL 6.2 02/45] ASoC: codecs: tx-macro: Fix for KASAN: slab-out-of-bounds Sasha Levin
2023-03-22 19:55 ` [PATCH AUTOSEL 6.2 03/45] ASoC: Intel: avs: max98357a: Explicitly define codec format Sasha Levin
2023-03-22 19:55 ` [PATCH AUTOSEL 6.2 04/45] ASoC: Intel: avs: da7219: " Sasha Levin
2023-03-22 19:55 ` [PATCH AUTOSEL 6.2 05/45] ASoC: Intel: avs: rt5682: " Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 06/45] ASoC: Intel: avs: ssm4567: Remove nau8825 bits Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 07/45] ASoC: Intel: avs: nau8825: Adjust clock control Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 08/45] lib: zstd: Backport fix for in-place decompression Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 09/45] zstd: Fix definition of assert() Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 10/45] ACPI: video: Add backlight=native DMI quirk for Dell Vostro 15 3535 Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 11/45] ACPI: x86: Introduce an acpi_quirk_skip_gpio_event_handlers() helper Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 12/45] ACPI: x86: Add skip i2c clients quirk for Acer Iconia One 7 B1-750 Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 13/45] ACPI: x86: Add skip i2c clients quirk for Lenovo Yoga Book X90 Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 14/45] ASoC: SOF: ipc3: Check for upper size limit for the received message Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 15/45] ASoC: SOF: ipc4-topology: Fix incorrect sample rate print unit Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 16/45] ASoC: SOF: Intel: pci-tng: revert invalid bar size setting Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 17/45] ASoC: SOF: Intel: hda-dsp: harden D0i3 programming sequence Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 18/45] ASoC: SOF: Intel: hda-ctrl: re-add sleep after entering and exiting reset Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 19/45] ASoC: SOF: IPC4: update gain ipc msg definition to align with fw Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 20/45] ASoC: hdmi-codec: only startup/shutdown on supported streams Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 21/45] wifi: mac80211: check basic rates validity Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 22/45] md: avoid signed overflow in slot_store() Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 23/45] x86/PVH: obtain VGA console info in Dom0 Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 24/45] drm/amdkfd: Fix BO offset for multi-VMA page migration Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 25/45] drm/amdkfd: fix a potential double free in pqm_create_queue Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 26/45] drm/amdgpu/vcn: custom video info caps for sriov Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 27/45] drm/amdkfd: fix potential kgd_mem UAFs Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 28/45] drm/amd/display: Fix HDCP failing to enable after suspend Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 29/45] net: hsr: Don't log netdev_err message on unknown prp dst node Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 30/45] ALSA: asihpi: check pao in control_message() Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 31/45] ALSA: hda/ca0132: fixup buffer overrun at tuning_ctl_set() Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 32/45] fbdev: tgafb: Fix potential divide by zero Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 33/45] ACPI: tools: pfrut: Check if the input of level and type is in the right numeric range Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 34/45] sched_getaffinity: don't assume 'cpumask_size()' is fully initialized Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 35/45] nvme-pci: fixing memory leak in probe teardown path Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 36/45] nvme-pci: add NVME_QUIRK_BOGUS_NID for Lexar NM620 Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 37/45] drm/amdkfd: Fixed kfd_process cleanup on module exit Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 38/45] net/mlx5e: Lower maximum allowed MTU in XSK to match XDP prerequisites Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 39/45] fbdev: nvidia: Fix potential divide by zero Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 40/45] fbdev: intelfb: " Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 41/45] fbdev: lxfb: " Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 42/45] fbdev: au1200fb: " Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 43/45] tools/power turbostat: Fix /dev/cpu_dma_latency warnings Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 44/45] tools/power turbostat: fix decoding of HWP_STATUS Sasha Levin
2023-03-22 19:56 ` [PATCH AUTOSEL 6.2 45/45] tracing: Fix wrong return in kprobe_event_gen_test.c Sasha Levin

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®