From patchwork Tue Aug 20 16:08:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13770446 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 09CB773176 for ; Tue, 20 Aug 2024 16:09:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724170144; cv=none; b=rbacPfj2b8DPrJ2QvTzsZzX9Zz+tYfwp5senk2Tg0tQ0DykLV0MwlWnL7UXVn4qTTcEuttT89YokgEAej10A9G9isF6t88Ad20z98rTuhFhp/jrke5dDw0ioiV08Jivwri9aVWw/EwJo0XbflkLdfh1hX2nTfbOTTvGFzNSHViw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724170144; c=relaxed/simple; bh=yS1UHtxKu2vJvZldY7H0NQ3WDbNnEubzUtpgcSV5t28=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=LBZa++JP2EgYwrpoAoEzSozDokkGQ8nhbTlFbspyXWiOUxF4JJtVP+LlTehWmX2yTIeOYE56NhHnRGI5QZZGKFZ+MUve23O6MPoOXa76/0oajreXGafvmiJN8VyXKCw3Wdb685zDOq/v9cRf5nxU4LASD9dUnRdPuqJR99+4nqk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=pqHa9hmD; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="pqHa9hmD" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e164e64efb6so1717583276.3 for ; Tue, 20 Aug 2024 09:09:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1724170142; x=1724774942; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=SnUUgkJ/RsB+uQyEP8JntMqtRgYYJBc8/3pB/5cqAv4=; b=pqHa9hmDsNshQulofO2nr/d77xS11w8KY5CLH+zMjxsai1hOVGox6Z16Z5JO945L8b x1RUnu4IcilDF2fCe645KHpfvkF9vw8D7eagWFDz0/jlmNeygvHXs7QLeTUtV/lRX0DC KJKFOyzLhEn9E0Y3rWhdNomKRDGuEnBOVAD6/mlfyihHepLySEI0aFsKLISwpJvTbhqH cDWoDdhZrVAd3QrFDlCsjrEvKesEoBl3+/WSi1RL4RnnTrDoOhxzvLysemmMm2QRYxnc NZ6RCDPlUrnxP5Qk16y93QKvoc7KEfhc+MaUU+UiLq1Z63pEBFwC9VQ7ASB9P/0ViJsd BW1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724170142; x=1724774942; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SnUUgkJ/RsB+uQyEP8JntMqtRgYYJBc8/3pB/5cqAv4=; b=mI8i4+r8f7I4FjRD/95l0TcVwGclQU2nbsdeaqbkrOLT/N+avVo1K2KKPkvRqHoC37 3sUl/qMImEApZ+tTBFXYjrHupnN9qLrkivb+KHjIM6wsVO0XPQ6qmIVWPRuXog5UoKO5 ebevEHdtI42UhVAnyPotUFPZEjxR8dAtFQnxNAGKV45xeSXzOWkmeGz5svHz55HOo490 81JTPIbmQtRaVUpOMm/c07GWRih/R+yFsQnchTvMpjWXR63/jxzjY82Q0SaRaPd8Zg5u LsHU2U7Npk5ZyaRy+aAOSGjZuiQ7KHNOKDzX3K2e78btaPIpAuYBucM6zWg41PxOW4r2 m1qA== X-Forwarded-Encrypted: i=1; AJvYcCU1qwOk9SSL6x3Bo71bZEKDM6+UEW3J6dhlkh7TurkA5+o9DxspMQ5xU6Zt1BD7kMnGN+E2YqduRQSQhNW+Qqjug4V5vubI X-Gm-Message-State: AOJu0YzelcWwRxJnWEGvAOD9Qoy0F4Hu56rh7LDXyd2WZ7ffYa/aE1Oe HpFF1yuPJG0KrJsgwkY3FeJfS6E6fNGOMrDG6JgwptSPmmVytPqkR37hMx0539WuH5oweNAzhrM rm1fWVVcUNA== X-Google-Smtp-Source: AGHT+IGbmtG7uoiV8kQRBcgvgVk7quhRDx0eaLkiSVBZ7hbTTbCuPeM6VeV+avGjla6i2RfhLXE0/sKOUHXoZg== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:bccd:0:b0:e0b:f1fd:1375 with SMTP id 3f1490d57ef6-e1180f732a0mr29064276.10.1724170141865; Tue, 20 Aug 2024 09:09:01 -0700 (PDT) Date: Tue, 20 Aug 2024 16:08:57 +0000 In-Reply-To: <20240820160859.3786976-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240820160859.3786976-1-edumazet@google.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Message-ID: <20240820160859.3786976-2-edumazet@google.com> Subject: [PATCH v2 net 1/3] ipv6: prevent UAF in ip6_send_skb() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: David Ahern , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet , syzbot X-Patchwork-Delegate: kuba@kernel.org syzbot reported an UAF in ip6_send_skb() [1] After ip6_local_out() has returned, we no longer can safely dereference rt, unless we hold rcu_read_lock(). A similar issue has been fixed in commit a688caa34beb ("ipv6: take rcu lock in rawv6_send_hdrinc()") Another potential issue in ip6_finish_output2() is handled in a separate patch. [1] BUG: KASAN: slab-use-after-free in ip6_send_skb+0x18d/0x230 net/ipv6/ip6_output.c:1964 Read of size 8 at addr ffff88806dde4858 by task syz.1.380/6530 CPU: 1 UID: 0 PID: 6530 Comm: syz.1.380 Not tainted 6.11.0-rc3-syzkaller-00306-gdf6cbc62cc9b #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024 Call Trace: __dump_stack lib/dump_stack.c:93 [inline] dump_stack_lvl+0x241/0x360 lib/dump_stack.c:119 print_address_description mm/kasan/report.c:377 [inline] print_report+0x169/0x550 mm/kasan/report.c:488 kasan_report+0x143/0x180 mm/kasan/report.c:601 ip6_send_skb+0x18d/0x230 net/ipv6/ip6_output.c:1964 rawv6_push_pending_frames+0x75c/0x9e0 net/ipv6/raw.c:588 rawv6_sendmsg+0x19c7/0x23c0 net/ipv6/raw.c:926 sock_sendmsg_nosec net/socket.c:730 [inline] __sock_sendmsg+0x1a6/0x270 net/socket.c:745 sock_write_iter+0x2dd/0x400 net/socket.c:1160 do_iter_readv_writev+0x60a/0x890 vfs_writev+0x37c/0xbb0 fs/read_write.c:971 do_writev+0x1b1/0x350 fs/read_write.c:1018 do_syscall_x64 arch/x86/entry/common.c:52 [inline] do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f936bf79e79 Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007f936cd7f038 EFLAGS: 00000246 ORIG_RAX: 0000000000000014 RAX: ffffffffffffffda RBX: 00007f936c115f80 RCX: 00007f936bf79e79 RDX: 0000000000000001 RSI: 0000000020000040 RDI: 0000000000000004 RBP: 00007f936bfe7916 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 0000000000000000 R14: 00007f936c115f80 R15: 00007fff2860a7a8 Allocated by task 6530: kasan_save_stack mm/kasan/common.c:47 [inline] kasan_save_track+0x3f/0x80 mm/kasan/common.c:68 unpoison_slab_object mm/kasan/common.c:312 [inline] __kasan_slab_alloc+0x66/0x80 mm/kasan/common.c:338 kasan_slab_alloc include/linux/kasan.h:201 [inline] slab_post_alloc_hook mm/slub.c:3988 [inline] slab_alloc_node mm/slub.c:4037 [inline] kmem_cache_alloc_noprof+0x135/0x2a0 mm/slub.c:4044 dst_alloc+0x12b/0x190 net/core/dst.c:89 ip6_blackhole_route+0x59/0x340 net/ipv6/route.c:2670 make_blackhole net/xfrm/xfrm_policy.c:3120 [inline] xfrm_lookup_route+0xd1/0x1c0 net/xfrm/xfrm_policy.c:3313 ip6_dst_lookup_flow+0x13e/0x180 net/ipv6/ip6_output.c:1257 rawv6_sendmsg+0x1283/0x23c0 net/ipv6/raw.c:898 sock_sendmsg_nosec net/socket.c:730 [inline] __sock_sendmsg+0x1a6/0x270 net/socket.c:745 ____sys_sendmsg+0x525/0x7d0 net/socket.c:2597 ___sys_sendmsg net/socket.c:2651 [inline] __sys_sendmsg+0x2b0/0x3a0 net/socket.c:2680 do_syscall_x64 arch/x86/entry/common.c:52 [inline] do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83 entry_SYSCALL_64_after_hwframe+0x77/0x7f Freed by task 45: kasan_save_stack mm/kasan/common.c:47 [inline] kasan_save_track+0x3f/0x80 mm/kasan/common.c:68 kasan_save_free_info+0x40/0x50 mm/kasan/generic.c:579 poison_slab_object+0xe0/0x150 mm/kasan/common.c:240 __kasan_slab_free+0x37/0x60 mm/kasan/common.c:256 kasan_slab_free include/linux/kasan.h:184 [inline] slab_free_hook mm/slub.c:2252 [inline] slab_free mm/slub.c:4473 [inline] kmem_cache_free+0x145/0x350 mm/slub.c:4548 dst_destroy+0x2ac/0x460 net/core/dst.c:124 rcu_do_batch kernel/rcu/tree.c:2569 [inline] rcu_core+0xafd/0x1830 kernel/rcu/tree.c:2843 handle_softirqs+0x2c4/0x970 kernel/softirq.c:554 __do_softirq kernel/softirq.c:588 [inline] invoke_softirq kernel/softirq.c:428 [inline] __irq_exit_rcu+0xf4/0x1c0 kernel/softirq.c:637 irq_exit_rcu+0x9/0x30 kernel/softirq.c:649 instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1043 [inline] sysvec_apic_timer_interrupt+0xa6/0xc0 arch/x86/kernel/apic/apic.c:1043 asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:702 Last potentially related work creation: kasan_save_stack+0x3f/0x60 mm/kasan/common.c:47 __kasan_record_aux_stack+0xac/0xc0 mm/kasan/generic.c:541 __call_rcu_common kernel/rcu/tree.c:3106 [inline] call_rcu+0x167/0xa70 kernel/rcu/tree.c:3210 refdst_drop include/net/dst.h:263 [inline] skb_dst_drop include/net/dst.h:275 [inline] nf_ct_frag6_queue net/ipv6/netfilter/nf_conntrack_reasm.c:306 [inline] nf_ct_frag6_gather+0xb9a/0x2080 net/ipv6/netfilter/nf_conntrack_reasm.c:485 ipv6_defrag+0x2c8/0x3c0 net/ipv6/netfilter/nf_defrag_ipv6_hooks.c:67 nf_hook_entry_hookfn include/linux/netfilter.h:154 [inline] nf_hook_slow+0xc3/0x220 net/netfilter/core.c:626 nf_hook include/linux/netfilter.h:269 [inline] __ip6_local_out+0x6fa/0x800 net/ipv6/output_core.c:143 ip6_local_out+0x26/0x70 net/ipv6/output_core.c:153 ip6_send_skb+0x112/0x230 net/ipv6/ip6_output.c:1959 rawv6_push_pending_frames+0x75c/0x9e0 net/ipv6/raw.c:588 rawv6_sendmsg+0x19c7/0x23c0 net/ipv6/raw.c:926 sock_sendmsg_nosec net/socket.c:730 [inline] __sock_sendmsg+0x1a6/0x270 net/socket.c:745 sock_write_iter+0x2dd/0x400 net/socket.c:1160 do_iter_readv_writev+0x60a/0x890 Fixes: 0625491493d9 ("ipv6: ip6_push_pending_frames() should increment IPSTATS_MIB_OUTDISCARDS") Signed-off-by: Eric Dumazet Reported-by: syzbot Reviewed-by: David Ahern --- net/ipv6/ip6_output.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index ab504d31f0cdd8dec9ab01bf9d6e6517307609cd..f7b53effc80f8b3b7a839f58097d021a11f9eb37 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -1956,6 +1956,7 @@ int ip6_send_skb(struct sk_buff *skb) struct rt6_info *rt = dst_rt6_info(skb_dst(skb)); int err; + rcu_read_lock(); err = ip6_local_out(net, skb->sk, skb); if (err) { if (err > 0) @@ -1965,6 +1966,7 @@ int ip6_send_skb(struct sk_buff *skb) IPSTATS_MIB_OUTDISCARDS); } + rcu_read_unlock(); return err; } From patchwork Tue Aug 20 16:08:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13770447 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5721D196DA2 for ; Tue, 20 Aug 2024 16:09:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724170145; cv=none; b=DpvgoGXieiW9b4Un7dm8eGgnEMVZp5MuC0q8fEYDRGkh9Uojqdg85YFInyd0SfGMAQlyGF1cijl7Y3jvtMtPjtMY/KyDBCR+XLtuH83QptDBBJ8CZkaY64KBvFmmQPDdPpGErhZ5l4NtxBlmShW3UPCrVHFWcBx9/i0JHDf2xPI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724170145; c=relaxed/simple; bh=hzivC0QY8/OrDsjl0zLN3oA5RAsMUhmZXb81iP5BZzk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=b0g0lObc6NqNpHkKA/1H/JCCGLM5rFd+vZPGc92L2UOMqB0NfbXQx7PrPT0yfKt9m6vopCG2Fd5LPjCH8h1lIU9IH7wlIuBiiZtFdrcqsjmR6srFUEVEau4jhR0KpTmg30VhTMV9ItFfPc+ifYv4IzCEQdlagiwry6vp4uTXY3o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=s477pmNs; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="s477pmNs" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e1159fb1669so8879314276.2 for ; Tue, 20 Aug 2024 09:09:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1724170143; x=1724774943; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=E28CXQYWoYPohvZg7/J6bFm5MrC6YxPoWTodXDcnZFU=; b=s477pmNspAhYOdK63QYtOnb0UnpNN7C77ZByfTtQ1nz04UJeImqfuIP3bbJ/s+76zb dP0yLEeUBZfp/qxwZ6FiPi8jfwTABgwAV4jNr9BUHd1nHa8PXnF1Xp+U06KuRu80mHBS JciIQrK7W99+CDrHEtFLlL7z3IQ+a1ATyG9496is3RCzD2vwOqgkg+A12PtoZQszAGU+ jLmWCRQWSe8AhDGOCTP4I1wGNjU2tGP5VJnqXQfD1XoiRFfM3d3UXDOJdcZ8VIi/Wb7P 1GoQfB2UJiuMpUeids74D9lXvADLjKLoYZNF6Q5nanFfldZ6GfbMdgo1AlmXqOXuaAVV HN5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724170143; x=1724774943; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=E28CXQYWoYPohvZg7/J6bFm5MrC6YxPoWTodXDcnZFU=; b=hX8SRtCpw8mp1V9UZItMrJ2I0HSHgiOWtm05el8BrB0m7CfNCCHFWCn/B2S1CsKSAH JG2V3WjfANb4XDS92pNXZD8aCHXAjqs3Iu9F+9WUuMkflH6Mez/oxtIe8bxlQVk8xkcx PK1JV08RbnufMi1pRhgD6u+6nIu0WEq4Ptyxoh7AwhU+4noB27hsLhlgNsUyibpfs7kL 67IiFVWivIMf8vgiuxg2PHm4tQjOhXdDGr8T/kcdduuTddEJwTMyMX08WrYR6k4UgT1o VIreuzY6su6Cfn9Va1OkEoX5ngCN+BtGg8Ty9aS+cqsgKYQUSTs95i1dXrhrUgoeRNLX Lb6A== X-Forwarded-Encrypted: i=1; AJvYcCU6ozqCAan5hhujHXfQmOcIoxQDBhCRjOcUNERRxQn7axFdmPh5+dW7VePV0wHlViNfsq/2vNw7MwRbc9d3sGveG5Z3USBG X-Gm-Message-State: AOJu0YyGEMumuYRA0dEem6G+b32yx7DRBu8YFW9rrYV1iu1+CTnM05/8 4AYdLVSY4lm4gZDMqq9/ieDXuPhY7fgOjldz/TjOtxPe/n+zT+LMKOlfyktRfnonfakiwuGwb6V ASJYFUSpE9g== X-Google-Smtp-Source: AGHT+IEiwzkJmAE73h3qQODbSuiTDrrRPohI/cfxQYGO30HPZULd9EBV8unoa9anfmWGobB5mhyxt6zE2fRO6A== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a5b:943:0:b0:e0e:445b:606 with SMTP id 3f1490d57ef6-e1180b9df3emr32369276.0.1724170143291; Tue, 20 Aug 2024 09:09:03 -0700 (PDT) Date: Tue, 20 Aug 2024 16:08:58 +0000 In-Reply-To: <20240820160859.3786976-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240820160859.3786976-1-edumazet@google.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Message-ID: <20240820160859.3786976-3-edumazet@google.com> Subject: [PATCH v2 net 2/3] ipv6: fix possible UAF in ip6_finish_output2() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: David Ahern , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet , Vasily Averin X-Patchwork-Delegate: kuba@kernel.org If skb_expand_head() returns NULL, skb has been freed and associated dst/idev could also have been freed. We need to hold rcu_read_lock() to make sure the dst and associated idev are alive. Fixes: 5796015fa968 ("ipv6: allocate enough headroom in ip6_finish_output2()") Signed-off-by: Eric Dumazet Cc: Vasily Averin Reviewed-by: David Ahern --- net/ipv6/ip6_output.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index f7b53effc80f8b3b7a839f58097d021a11f9eb37..1b9ebee7308f02a626c766de1794e6b114ae8554 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -70,11 +70,15 @@ static int ip6_finish_output2(struct net *net, struct sock *sk, struct sk_buff * /* Be paranoid, rather than too clever. */ if (unlikely(hh_len > skb_headroom(skb)) && dev->header_ops) { + /* Make sure idev stays alive */ + rcu_read_lock(); skb = skb_expand_head(skb, hh_len); if (!skb) { IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTDISCARDS); + rcu_read_unlock(); return -ENOMEM; } + rcu_read_unlock(); } hdr = ipv6_hdr(skb); From patchwork Tue Aug 20 16:08:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13770448 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D04051A01BF for ; Tue, 20 Aug 2024 16:09:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724170147; cv=none; b=HQF4quYqdbIxjCm0YbeasZuipSr6RCyEnfeQVamfYDfEjjmvLe30bR/TBN1P5QvvDOY5yOYcnOiOUdgjvZqThUTvfueWVSzI4niTf0SUOZKK2c5yGChie4abRfpIcvznBqi5ymTRymjcv1dKkxbrU1Y1hNSetoGChaCYas4cvGg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724170147; c=relaxed/simple; bh=cBxJXRv1j7JPSGU5x07vrhxOOjZMJkC6Cbyjhtc1Ib8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=QSuWFCJZUXnAgMIE8/LurkosfvDJrZY+aIltrq+blNWc3oOznP5Xdwn0bbHsz1bxux8IXubDkn5/Pr1fk/SmLHpQ1Y7npwRCPxinCrk5CZaGQn5k1n1wrAzVYoFHMNAElGTBDrvdQHjCvAv83PBvdOIJtLiOXV96iYb04RnPRio= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ws81Y0Qj; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ws81Y0Qj" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6b41e02c255so67865157b3.3 for ; Tue, 20 Aug 2024 09:09:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1724170145; x=1724774945; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Pdf5j74DbpMUw4v4CbxVsm1FC9sUV/TYhieddF+Uvwg=; b=ws81Y0QjveJUA/6X25roMMszxfh2VrzG8I0l0zXTjNOW4s+sHB1DWTCz/eAYtHS83C Le/WY9r26g0OFpQhiQ5DNW7S81fat6rMF7P272A4WXyVef3zyHwFIP4c3L/WLEpd780t +GsUs9IhQpbcqFsXdo+KNxdjIN3aSc4korBoawT5YtML2f96BtNiA6JFmO4E7D6Ezlfh h8bw84h+otWX0oZar6zVprONpaUod5wKtuQ/SDBuxYeoSn0GO7YdP4m8hlTHkxpa81Xp 4s9LS7nHqmXltUsU6nkZo9x706EX8DZGpVDSqdIK4JSRweVLMNF8LebRzqlJXpr7EGNj Nr9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724170145; x=1724774945; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Pdf5j74DbpMUw4v4CbxVsm1FC9sUV/TYhieddF+Uvwg=; b=r54Yk0ftgdfvBX6fFqzmI8q5Xduh3hijo96+sqNqP0fAvNUelLQtmxWZOFdGdzdhX5 H9NHf5bmJvlpXk9o7YW6Jl8N3b2o9WBhDQmJg+ld1Er616Z/X2Xym3pNEes7AEDCmR/I ubFi6zB+IOxokes6l5OwyM9T+qW6wWb12HAiPeX/hplVNu/TePrq7lxPkJCLmXIu5dAB mR7s8r3yHsAQaV++WDKi1diniJ2CbvTCDloce8AQlwYZa98KW2cAlv0pzoBkktZob9pb dXtdMNNHuf9rlhevXU2cNfdgOMDGEtOlALAHZbmKAg4hFJGyBzFAbX8QDwFvDaLUlFcU pLqA== X-Forwarded-Encrypted: i=1; AJvYcCXbVIo8OsBycWgmjrj8qzEK+77zPi3LhHbkRLEVwzqf0b7o1wzhJdnw4BjnjhdZLBKMiv1f4cG/xmrMf4ANvqoGcKKsgqfS X-Gm-Message-State: AOJu0YyOm3WJIpeTUspWQNMyLoPbngDZ6p/AVYU3MXsP5ae6tPzT5NgK iFjjcrejNiYFqwo5+EF9UzEYvHdo8Fik6eQM0Ai4Dhs+XfiItfXGAUhXPf4d9aQ6yHG/rOfd1WW kdmMz7HGfnw== X-Google-Smtp-Source: AGHT+IF/3GJpweV1K84wCnjMJEH5W2KvoH788u47Wd+dYPh+JbS2xQzXP29jafKM7X374IJYcqYC8r3OMdAAbg== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:690c:4f01:b0:69b:c01:82a5 with SMTP id 00721157ae682-6b1bbb4e422mr2148707b3.7.1724170144767; Tue, 20 Aug 2024 09:09:04 -0700 (PDT) Date: Tue, 20 Aug 2024 16:08:59 +0000 In-Reply-To: <20240820160859.3786976-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240820160859.3786976-1-edumazet@google.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Message-ID: <20240820160859.3786976-4-edumazet@google.com> Subject: [PATCH v2 net 3/3] ipv6: prevent possible UAF in ip6_xmit() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: David Ahern , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet , Vasily Averin X-Patchwork-Delegate: kuba@kernel.org If skb_expand_head() returns NULL, skb has been freed and the associated dst/idev could also have been freed. We must use rcu_read_lock() to prevent a possible UAF. Fixes: 0c9f227bee11 ("ipv6: use skb_expand_head in ip6_xmit") Signed-off-by: Eric Dumazet Cc: Vasily Averin Reviewed-by: David Ahern --- net/ipv6/ip6_output.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 1b9ebee7308f02a626c766de1794e6b114ae8554..f26841f1490f5c31e3b09bce5773391e779128e1 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -287,11 +287,15 @@ int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6, head_room += opt->opt_nflen + opt->opt_flen; if (unlikely(head_room > skb_headroom(skb))) { + /* Make sure idev stays alive */ + rcu_read_lock(); skb = skb_expand_head(skb, head_room); if (!skb) { IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTDISCARDS); + rcu_read_unlock(); return -ENOBUFS; } + rcu_read_unlock(); } if (opt) {