From patchwork Wed Sep 6 22:30:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuxuan Luo X-Patchwork-Id: 1830601 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=HoFlRUOL; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RgxtK22XXz1yh8 for ; Thu, 7 Sep 2023 08:31:20 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1qe13C-0003Fg-R4; Wed, 06 Sep 2023 22:31:06 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1qe137-0003Ea-8L for kernel-team@lists.ubuntu.com; Wed, 06 Sep 2023 22:31:01 +0000 Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id E4F593F32D for ; Wed, 6 Sep 2023 22:31:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1694039460; bh=MblIabZE2UGLLwm8VHf0RqK3OEhpXBIkh6kW0Hxqd88=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HoFlRUOLIUeEAZB/qJoYJLMEyDqvNOubNHBZAAmAF5LsIVIs7M7fpATo8Vtv8J3SP CqsexNAU7oX5imGfbnXW5v2IRFm2t8+B0U0GAYiC7/jSvKEDqEeLgFNsetsKqEZrWW jPPMrYb+fx/gIJTinluIs6vFSFlWsO9RzRUNleXUxJbs+HniZt0Y5KoId4/DTP+xlz IxMaD1LWD8i7Ky7i1igRMeCb1aK9VEeWykXu8KSJ7uuEnRbuBVXjQucr72p6eQSFaY 4qw0KXBhVYuNmVj6i3C0NSxbu+iYHmn1UBedShKDL/K+WvJVo8/cMJmrblDFzThYTv rrkHgSw6piUKA== Received: by mail-oi1-f200.google.com with SMTP id 5614622812f47-3ab3059eb0cso352641b6e.3 for ; Wed, 06 Sep 2023 15:31:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694039459; x=1694644259; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MblIabZE2UGLLwm8VHf0RqK3OEhpXBIkh6kW0Hxqd88=; b=WmvEW1U6w0krdsbDvkwdognnU0LvH/v1ICWyGbFLU9B6l20CKj71sw1oPZ6ToVPIRj GUnviiCM4Fqj6kN22VgG/BT8kHJM4pNGqCQKuMnSdobZf/NInGBhGsB8lVyGgdZPF2xr ALJGrq0+4Rshq+kN2xDwaXcScotTZhpeZyWb4DBS20IRE6S5ltZ3ycNzidA53DRU+5Rz 5Nt29yDfs67Ssguo455P17h1cbXTuUx8hNU8d206uSkI9EwoesVsLemqQXm0LrLOyiWA KFBbXdqOVKJWiBz7zu3jQYkP8lqYvP2CmGHPU/y+a95oTEB5a6hnnKidkwCaZRfqTR9b N+OA== X-Gm-Message-State: AOJu0YwIGDkjAsQnIpStqNrMhRj+vfDQwRtJQ4O+9MIHvJ1Mqhg1VdVg V6PBujtZGhXgLZuS407CqG62q2G7jeqhZUFlnKzV6tQz7ZP2jsi9xX9cBftjDxKrGDC/FZ6MKzL eDdxxZDyqh1UAK5AWy4KJpyLlXGYysYB9y1qYlwIwQP3ayij0ew== X-Received: by 2002:a05:6358:724c:b0:139:c390:f1f1 with SMTP id i12-20020a056358724c00b00139c390f1f1mr5170663rwa.23.1694039459226; Wed, 06 Sep 2023 15:30:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGxAAAX1F5+fOmAQPypV8io7A4KJa5hkHdHhmp4HxLZNWAThJhTCwNWTXdSrEtoMbDssMwJlg== X-Received: by 2002:a05:6358:724c:b0:139:c390:f1f1 with SMTP id i12-20020a056358724c00b00139c390f1f1mr5170634rwa.23.1694039458645; Wed, 06 Sep 2023 15:30:58 -0700 (PDT) Received: from cache-ubuntu.hsd1.nj.comcast.net ([2601:86:200:98b0:60d1:6245:8cf8:9b33]) by smtp.gmail.com with ESMTPSA id z3-20020a0cda83000000b0064f70c57531sm5787589qvj.57.2023.09.06.15.30.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Sep 2023 15:30:58 -0700 (PDT) From: Yuxuan Luo To: kernel-team@lists.ubuntu.com Subject: [SRU][J/L][PATCH 1/1] xfrm: add NULL check in xfrm_update_ae_params Date: Wed, 6 Sep 2023 18:30:55 -0400 Message-Id: <20230906223055.35186-3-yuxuan.luo@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230906223055.35186-1-yuxuan.luo@canonical.com> References: <20230906223055.35186-1-yuxuan.luo@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Lin Ma Normally, x->replay_esn and x->preplay_esn should be allocated at xfrm_alloc_replay_state_esn(...) in xfrm_state_construct(...), hence the xfrm_update_ae_params(...) is okay to update them. However, the current implementation of xfrm_new_ae(...) allows a malicious user to directly dereference a NULL pointer and crash the kernel like below. BUG: kernel NULL pointer dereference, address: 0000000000000000 PGD 8253067 P4D 8253067 PUD 8e0e067 PMD 0 Oops: 0002 [#1] PREEMPT SMP KASAN NOPTI CPU: 0 PID: 98 Comm: poc.npd Not tainted 6.4.0-rc7-00072-gdad9774deaf1 #8 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.qemu.o4 RIP: 0010:memcpy_orig+0xad/0x140 Code: e8 4c 89 5f e0 48 8d 7f e0 73 d2 83 c2 20 48 29 d6 48 29 d7 83 fa 10 72 34 4c 8b 06 4c 8b 4e 08 c RSP: 0018:ffff888008f57658 EFLAGS: 00000202 RAX: 0000000000000000 RBX: ffff888008bd0000 RCX: ffffffff8238e571 RDX: 0000000000000018 RSI: ffff888007f64844 RDI: 0000000000000000 RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000000 R12: ffff888008f57818 R13: ffff888007f64aa4 R14: 0000000000000000 R15: 0000000000000000 FS: 00000000014013c0(0000) GS:ffff88806d600000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000000 CR3: 00000000054d8000 CR4: 00000000000006f0 Call Trace: ? __die+0x1f/0x70 ? page_fault_oops+0x1e8/0x500 ? __pfx_is_prefetch.constprop.0+0x10/0x10 ? __pfx_page_fault_oops+0x10/0x10 ? _raw_spin_unlock_irqrestore+0x11/0x40 ? fixup_exception+0x36/0x460 ? _raw_spin_unlock_irqrestore+0x11/0x40 ? exc_page_fault+0x5e/0xc0 ? asm_exc_page_fault+0x26/0x30 ? xfrm_update_ae_params+0xd1/0x260 ? memcpy_orig+0xad/0x140 ? __pfx__raw_spin_lock_bh+0x10/0x10 xfrm_update_ae_params+0xe7/0x260 xfrm_new_ae+0x298/0x4e0 ? __pfx_xfrm_new_ae+0x10/0x10 ? __pfx_xfrm_new_ae+0x10/0x10 xfrm_user_rcv_msg+0x25a/0x410 ? __pfx_xfrm_user_rcv_msg+0x10/0x10 ? __alloc_skb+0xcf/0x210 ? stack_trace_save+0x90/0xd0 ? filter_irq_stacks+0x1c/0x70 ? __stack_depot_save+0x39/0x4e0 ? __kasan_slab_free+0x10a/0x190 ? kmem_cache_free+0x9c/0x340 ? netlink_recvmsg+0x23c/0x660 ? sock_recvmsg+0xeb/0xf0 ? __sys_recvfrom+0x13c/0x1f0 ? __x64_sys_recvfrom+0x71/0x90 ? do_syscall_64+0x3f/0x90 ? entry_SYSCALL_64_after_hwframe+0x72/0xdc ? copyout+0x3e/0x50 netlink_rcv_skb+0xd6/0x210 ? __pfx_xfrm_user_rcv_msg+0x10/0x10 ? __pfx_netlink_rcv_skb+0x10/0x10 ? __pfx_sock_has_perm+0x10/0x10 ? mutex_lock+0x8d/0xe0 ? __pfx_mutex_lock+0x10/0x10 xfrm_netlink_rcv+0x44/0x50 netlink_unicast+0x36f/0x4c0 ? __pfx_netlink_unicast+0x10/0x10 ? netlink_recvmsg+0x500/0x660 netlink_sendmsg+0x3b7/0x700 This Null-ptr-deref bug is assigned CVE-2023-3772. And this commit adds additional NULL check in xfrm_update_ae_params to fix the NPD. Fixes: d8647b79c3b7 ("xfrm: Add user interface for esn and big anti-replay windows") Signed-off-by: Lin Ma Reviewed-by: Leon Romanovsky Signed-off-by: Steffen Klassert (cherry picked from commit 00374d9b6d9f932802b55181be9831aa948e5b7c) CVE-2023-3772 Signed-off-by: Yuxuan Luo --- net/xfrm/xfrm_user.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c index 6794b9dea27aa..8333a44457dee 100644 --- a/net/xfrm/xfrm_user.c +++ b/net/xfrm/xfrm_user.c @@ -628,7 +628,7 @@ static void xfrm_update_ae_params(struct xfrm_state *x, struct nlattr **attrs, struct nlattr *rt = attrs[XFRMA_REPLAY_THRESH]; struct nlattr *mt = attrs[XFRMA_MTIMER_THRESH]; - if (re) { + if (re && x->replay_esn && x->preplay_esn) { struct xfrm_replay_state_esn *replay_esn; replay_esn = nla_data(re); memcpy(x->replay_esn, replay_esn,