Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp861539pxb; Tue, 1 Feb 2022 11:59:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJzducgEAxzZ/xNHc36vh+ko/qiRmDn6pRrJx5aqPfr8K64C3mFaoFVBoolElX1rR6X4iIFz X-Received: by 2002:a17:906:3b84:: with SMTP id u4mr22170965ejf.689.1643745569788; Tue, 01 Feb 2022 11:59:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643745569; cv=none; d=google.com; s=arc-20160816; b=wT/A6DFltloRQVTi88/ra7SdBGOMlEt6qC+LNwOLbRKhxT1i287BOXOkMWfKM182LW orwxR/UZLt9/dcV54vMqqMTrsZrxXoPCAig0CUg9c00fIfJzd5B/l35Y2JYVi3neESkq LY1E+4XQF8BHhpuNNr5BqbqFP2+4MQD3JHNwv5i0Uq9hvDqUrgKD5UkM3IO/f8ctGeBd aT+5x72BN6BSM8HPB8SYo5ucyLb0Pj9QWMv2ICYcA5JyVkVIGrWTVwM81ZsaxYiE78Zu 4kQBFYDxKVb+TY6/5uvcFO24zy13cm3dL5ps0Oe4MIt8hi/g7Ax0i67RCzCeQbqk6EQw NS4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=i3XhlfE1okUdL6AeSJbfQ/3iRv4tGNf3k2LG4RY8Yjw=; b=PkPPA3G0y1ft7sm/fgvopleqyedIjYEs8q1u1io83OHsVYMkhAJ/TsEKxfjT1+bcqD qjSc7j1/WpuJjTTeAb+if+0C9uy21JlvoCwEpryfpGVwbyCHGep7VcDPF0tYSfeE+25G yowRApqOzfoq1nmIvuzW08CA2TVrqN7BsIZgq7RA2feh43+P3K1OrbNRs9hMOVCw61nG aaXhl1jppNffGxKZpb/3lILWwyuh2SNqho+ASDtZDkf/Imi/XM8i+0+9K1MYw/LvutJW o8eC4NJmQHvtLemXOp+0e/EV4J9XI2fUdPEbPNolMnww9qWUlfCsf584p4r4SGH54cKh NlUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=f4GQWfyz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hq33si10772458ejc.365.2022.02.01.11.59.04; Tue, 01 Feb 2022 11:59:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=f4GQWfyz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358763AbiAaLKt (ORCPT + 99 others); Mon, 31 Jan 2022 06:10:49 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:53886 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235281AbiAaLGD (ORCPT ); Mon, 31 Jan 2022 06:06:03 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 9AA2FB82A5D; Mon, 31 Jan 2022 11:06:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B782BC340E8; Mon, 31 Jan 2022 11:05:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643627160; bh=8QpPn/EcYTTWSowcI/ZY+gOqZOAzFOy0LCORVktrvLE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f4GQWfyzoN+ZFT3ywCh2pxZgwhDXPJBZWxrVY7qrD0CF8eDEVml8b/hlnMEL7D5xI AouwoWKllYPLYX8Sg3mFnfZh06VRnjriVJ4jYaSA67DK6TyGZx1/TiiX6hRKL1mhAG 0I5yL0Tsvvtf2LA9WlSBTZL5COJ94WiblGNX+Who= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , syzbot , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 093/100] ipv4: raw: lock the socket in raw_bind() Date: Mon, 31 Jan 2022 11:56:54 +0100 Message-Id: <20220131105223.580898656@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220131105220.424085452@linuxfoundation.org> References: <20220131105220.424085452@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Dumazet [ Upstream commit 153a0d187e767c68733b8e9f46218eb1f41ab902 ] For some reason, raw_bind() forgot to lock the socket. BUG: KCSAN: data-race in __ip4_datagram_connect / raw_bind write to 0xffff8881170d4308 of 4 bytes by task 5466 on cpu 0: raw_bind+0x1b0/0x250 net/ipv4/raw.c:739 inet_bind+0x56/0xa0 net/ipv4/af_inet.c:443 __sys_bind+0x14b/0x1b0 net/socket.c:1697 __do_sys_bind net/socket.c:1708 [inline] __se_sys_bind net/socket.c:1706 [inline] __x64_sys_bind+0x3d/0x50 net/socket.c:1706 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x44/0xd0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x44/0xae read to 0xffff8881170d4308 of 4 bytes by task 5468 on cpu 1: __ip4_datagram_connect+0xb7/0x7b0 net/ipv4/datagram.c:39 ip4_datagram_connect+0x2a/0x40 net/ipv4/datagram.c:89 inet_dgram_connect+0x107/0x190 net/ipv4/af_inet.c:576 __sys_connect_file net/socket.c:1900 [inline] __sys_connect+0x197/0x1b0 net/socket.c:1917 __do_sys_connect net/socket.c:1927 [inline] __se_sys_connect net/socket.c:1924 [inline] __x64_sys_connect+0x3d/0x50 net/socket.c:1924 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x44/0xd0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x44/0xae value changed: 0x00000000 -> 0x0003007f Reported by Kernel Concurrency Sanitizer on: CPU: 1 PID: 5468 Comm: syz-executor.5 Not tainted 5.17.0-rc1-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Eric Dumazet Reported-by: syzbot Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/ipv4/raw.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c index 7d26e0f8bdaeb..5d95f80314f95 100644 --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c @@ -721,6 +721,7 @@ static int raw_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len) int ret = -EINVAL; int chk_addr_ret; + lock_sock(sk); if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in)) goto out; @@ -740,7 +741,9 @@ static int raw_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len) inet->inet_saddr = 0; /* Use device */ sk_dst_reset(sk); ret = 0; -out: return ret; +out: + release_sock(sk); + return ret; } /* -- 2.34.1