Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2016009lqp; Sat, 23 Mar 2024 22:06:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWhCrwIpsFfq5jGB5+4WTEgnZxu6SyARmuod1ftoUSqvqD2Az0bVewUswirn5EjORRgtmy39JcNqF0bRQ0p4YiwO11M+XsgAdphJv08xg== X-Google-Smtp-Source: AGHT+IEWbUc4GVm9k8i07ylWW2QHY2IcgjL9fbnx4/0vF61Griq1PI9+s7PAG0vtndfU8OaaAKRo X-Received: by 2002:a05:6870:1690:b0:229:7b26:fed5 with SMTP id j16-20020a056870169000b002297b26fed5mr4465535oae.1.1711256777984; Sat, 23 Mar 2024 22:06:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711256777; cv=pass; d=google.com; s=arc-20160816; b=cMp4fHFoKBR+jRMhVoNXm9e5jMHkBCAjFIlyCtWleldVGPnsSM7Vi+E7KHeLuyyIRt T83tDs7ufsWb42DV6zSJVBwHS+hQxeIghALG1pVtmQZziH3dt39pGE8zOrv9Xqsy3+gB MSHaXEnilQLxUB2Q8sMKdRPwoZD68lsC1bD5NlEaoqiv4qgHGPxDLq18tG2YbvvSh47p zcQQN6JbPk39y4Rx+IRKmD4ECMr33FPjuPBQ114+VUG3taryIQjFvEAqAqGn6fQgO2H7 LZPT+JRzZ6hA89E8N/zl+yeuFtc4oHnbsIhIjWTgF14vd+knTiVU4K1Mu9VnlhCR356V 0A4w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=9duXSLuXHV8vFOCQXD8+b0A+1FBJ4vf3M5EGD4lf1a4=; fh=sLqESMYZjoFfkSffOET8KVj6mkreMaZ7Vo+IzbC+eqs=; b=Hv7+1uqJYQUtPZzSMT6hrREKGE3t4H8O+asJkyfQf2S4avgKb/ldXNolKyR+S9KzDv EBIqMWktk+q/ZEvvz/qgd4WyQyz63M5rI7rUNyMkDkeR60sT5t7rsXDqYz6XRJKnoLEF A4UNio3BTnZHM3OYcTAouFwfmVVkV1cSAiIoPxpMacwGgFvY7kqNw+vOSUtJxCoydJFX lW+gZ3AIQt4iJvimSC/pauV77dnwTCxZUUgttIVl5GgpXKd6Aj+avCKRlgr96ftEim1o fQ6/tiTLEGV9eDU0zHuMehzDKjlKdSoaxrSktJKQ2yvVImbLfZEGUgYNDrzag5IkbvkJ Gzag==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IsWxc7XQ; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-112590-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112590-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id gu6-20020a056a004e4600b006e6ca4153absi2697253pfb.293.2024.03.23.22.06.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 22:06:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112590-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IsWxc7XQ; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-112590-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112590-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 71255281F92 for ; Sun, 24 Mar 2024 05:06:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 669631426F; Sun, 24 Mar 2024 05:06:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="IsWxc7XQ" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C44C8134BE for ; Sun, 24 Mar 2024 05:06:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711256767; cv=none; b=QBJqk9vu4s5O4ufO9Kplnew6jQg0ip0NwCv8OR9//L3pcBxDwV+pGcAUSN5+66UP8iZ0zCdQUZqjgCp5zRiEg2KwOoQ43Vp3BcAaTUGrnmySTf6TLsByNLAbhV5vRJowQDswTjJSW80QDlsyCs+OIk+TpZHnM60ebpu4mKYU5v8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711256767; c=relaxed/simple; bh=R1JIMxCTBe/b+a+qC/2RObOqzW1ENmG9//PB/KrwKSk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=fhrpI3iqk53A4dhGlYUlaI1kjYhttsdLtQhq751XMyZyKyw+qeMExE5bYnxoNtZvYXyIeOLuXMzx7OSswoUmB0LeRjSvh3LFgOmUMY/tMENBlf4gLhaPlHBNoQYakwmg001s/7gjp8oMGwlpD02ZNYJEZumKzB6EYw71pEu/FJE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=IsWxc7XQ; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711256764; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=9duXSLuXHV8vFOCQXD8+b0A+1FBJ4vf3M5EGD4lf1a4=; b=IsWxc7XQy+23Kn2VKyuHSyCdcvpyVeBI6GY0/jAiCxsK11kQUCDCspyVe/Rp2M6OK3e9w/ AtwiroKmu4Jyp9ra0N5RwUuTn39LkGt46/lz4xtZhdfR8HjMbNWYxW7lSsKwxx4XxoT4Qy yNG7UG+dq073QkrqDLJ4Sct4bWNMqHU= Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-455-NZMH7caLMYugY4ZG_wyl1w-1; Sun, 24 Mar 2024 01:06:02 -0400 X-MC-Unique: NZMH7caLMYugY4ZG_wyl1w-1 Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-5ca5b61c841so2208365a12.3 for ; Sat, 23 Mar 2024 22:06:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711256761; x=1711861561; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=9duXSLuXHV8vFOCQXD8+b0A+1FBJ4vf3M5EGD4lf1a4=; b=XWz6MJMLPhYmXruLBv3nJbfMc0Id6psURohJ5ZEpF0J78YKkeRSTaCuOCcmKspEbg0 Uv7k18CsipSST8LnAs9EXHhfgD6aCUFz5Jsnt8KmPP4+GgFsgEaemIboaksqnU+OGQb5 U/yXmbeBmsM8sz9ID/O+MZSxvKBILVa4LcYcFWL6+VzWQTugEcsIwBD6ItmgH4+Mskvf wDkwwmohecqevwSYzeCJC5pOU1SwoQ3AKneuAVG/PmC1lVkwducZchTObq539gMEV5qQ tNTQM9g6FUqpvV81iqteuqvzycuHP/6RLyZHOBtj5w11IS8iT0NjkUNMJtoEL9euM00j Gssg== X-Forwarded-Encrypted: i=1; AJvYcCXPW7ut24vAdNJ/hAIR1zp2/rJY/cWjmOyE1rBsqU4qV4rdbut8rm3AQRcbfLywZMhRxnixnQ020ssgDK8qLnAg2nulJtTA5C1nbOP/ X-Gm-Message-State: AOJu0YzSEJEgRFNtAdY7y5JKy461Qa6JocwXKo0vb4VmdQXnHgDy4J7R kQ7j0zeEB2LTyXvbrjlRYSAHvwUeIqQ1w+MUz5IZOpuKTzWw7+kfrzNDfLdxpBO4z2/2FUpmZ4K ekU/9406UNfOLVCVm3wQd1V8TpXy2NxnwCLq3GXht2ZdGfBNQvLY8J4qIrhRz8g== X-Received: by 2002:a17:902:6ac9:b0:1dd:d431:3388 with SMTP id i9-20020a1709026ac900b001ddd4313388mr3044294plt.68.1711256761167; Sat, 23 Mar 2024 22:06:01 -0700 (PDT) X-Received: by 2002:a17:902:6ac9:b0:1dd:d431:3388 with SMTP id i9-20020a1709026ac900b001ddd4313388mr3044285plt.68.1711256760796; Sat, 23 Mar 2024 22:06:00 -0700 (PDT) Received: from kernel-devel.local ([240d:1a:c0d:9f00:6883:65ff:fe1c:cf69]) by smtp.gmail.com with ESMTPSA id x16-20020a1709027c1000b001dc486f0cbesm2379329pll.222.2024.03.23.22.05.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 22:06:00 -0700 (PDT) From: Shigeru Yoshida To: davem@davemloft.net, dsahern@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Shigeru Yoshida , syzkaller Subject: [PATCH net] ipv4: Fix uninit-value access in __ip_make_skb() Date: Sun, 24 Mar 2024 14:05:54 +0900 Message-ID: <20240324050554.1609460-1-syoshida@redhat.com> X-Mailer: git-send-email 2.44.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit KMSAN reported uninit-value access in __ip_make_skb() [1]. __ip_make_skb() tests HDRINCL to know if the skb has icmphdr. However, HDRINCL can cause a race condition. If calling setsockopt(2) with IP_HDRINCL changes HDRINCL while __ip_make_skb() is running, the function will access icmphdr in the skb even if it is not included. This causes the issue reported by KMSAN. Check FLOWI_FLAG_KNOWN_NH on fl4->flowi4_flags instead of testing HDRINCL on the socket. [1] BUG: KMSAN: uninit-value in __ip_make_skb+0x2b74/0x2d20 net/ipv4/ip_output.c:1481 __ip_make_skb+0x2b74/0x2d20 net/ipv4/ip_output.c:1481 ip_finish_skb include/net/ip.h:243 [inline] ip_push_pending_frames+0x4c/0x5c0 net/ipv4/ip_output.c:1508 raw_sendmsg+0x2381/0x2690 net/ipv4/raw.c:654 inet_sendmsg+0x27b/0x2a0 net/ipv4/af_inet.c:851 sock_sendmsg_nosec net/socket.c:730 [inline] __sock_sendmsg+0x274/0x3c0 net/socket.c:745 __sys_sendto+0x62c/0x7b0 net/socket.c:2191 __do_sys_sendto net/socket.c:2203 [inline] __se_sys_sendto net/socket.c:2199 [inline] __x64_sys_sendto+0x130/0x200 net/socket.c:2199 do_syscall_64+0xd8/0x1f0 arch/x86/entry/common.c:83 entry_SYSCALL_64_after_hwframe+0x6d/0x75 Uninit was created at: slab_post_alloc_hook mm/slub.c:3804 [inline] slab_alloc_node mm/slub.c:3845 [inline] kmem_cache_alloc_node+0x5f6/0xc50 mm/slub.c:3888 kmalloc_reserve+0x13c/0x4a0 net/core/skbuff.c:577 __alloc_skb+0x35a/0x7c0 net/core/skbuff.c:668 alloc_skb include/linux/skbuff.h:1318 [inline] __ip_append_data+0x49ab/0x68c0 net/ipv4/ip_output.c:1128 ip_append_data+0x1e7/0x260 net/ipv4/ip_output.c:1365 raw_sendmsg+0x22b1/0x2690 net/ipv4/raw.c:648 inet_sendmsg+0x27b/0x2a0 net/ipv4/af_inet.c:851 sock_sendmsg_nosec net/socket.c:730 [inline] __sock_sendmsg+0x274/0x3c0 net/socket.c:745 __sys_sendto+0x62c/0x7b0 net/socket.c:2191 __do_sys_sendto net/socket.c:2203 [inline] __se_sys_sendto net/socket.c:2199 [inline] __x64_sys_sendto+0x130/0x200 net/socket.c:2199 do_syscall_64+0xd8/0x1f0 arch/x86/entry/common.c:83 entry_SYSCALL_64_after_hwframe+0x6d/0x75 Fixes: 99e5acae193e ("ipv4: Fix potential uninit variable access bug in __ip_make_skb()") Reported-by: syzkaller Signed-off-by: Shigeru Yoshida --- I think IPv6 has a similar issue. If this patch is accepted, I will send a patch for IPv6. --- net/ipv4/ip_output.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index 1fe794967211..39229fd0601a 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -1473,7 +1473,7 @@ struct sk_buff *__ip_make_skb(struct sock *sk, * by icmp_hdr(skb)->type. */ if (sk->sk_type == SOCK_RAW && - !inet_test_bit(HDRINCL, sk)) + !(fl4->flowi4_flags & FLOWI_FLAG_KNOWN_NH)) icmp_type = fl4->fl4_icmp_type; else icmp_type = icmp_hdr(skb)->type; -- 2.44.0