Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1711217pxb; Wed, 9 Feb 2022 02:51:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJy5kVvWFqGBrTwfzZhc9afuISvtK47D7sKgBjFaEcfvrciEbKv48lZL3UQmsdzGK4h0Gb74 X-Received: by 2002:a65:4088:: with SMTP id t8mr1387935pgp.241.1644403905623; Wed, 09 Feb 2022 02:51:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644403905; cv=none; d=google.com; s=arc-20160816; b=VfbzGkTlcuE3OqFk0PM9d/yOTU379SeEnQnaFKg6r+rHa9EQHXhcthsJWHLyRWFJF2 KCRL0CQSbfbrJD6yDdPI97gau4PgPk9vnR6KFwB7k83kUnYJYvTdcL3BESVqVMnFdC30 KBSoazN+OXofmefjPS9aTeUOa+OCwSKE9EAjXcfERC+vicBFBYG8oQVO+q7GDwZPKvFG 0rqw3xTFcePhk1YCuqvw40698sCIivrG/Bvnu028dS7noLKbs03EDN+Pq0+BuXEoDXHZ XZi9XYXTuJptRFlusOv6TpK5wsMyOIWP9EsD8MXVFsb2AO8KPVUSRo1qFapvCrhTyJuK QVcA== 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=4WHmk9n7xKh1Q4lgHUzVj3qDMfXwBCYgEEiB2uQM0cs=; b=rLeWRyRZd0I2K7SDk0CL+hXhq7IuatdsPe/Jafv4gLFgJUDBrAjC7rfue+71GKy9Sz Qmsb8JXqeK7viMfgUA9ItTqXK14iCpwJG31pQVcEui0jI5wprEJqIPsh8DNFfTg1RzL7 BobeO4HzBAMLTplGST3T0GrQUoJOyRI7R2dBmiDoDP0pkyD/gaFyAq8YIDITnmIWv3Ka cQONLADVtZ4F9m18IkhyAysH13YgT0wGhtBO8TYt9sW57L4Yn894sk8jpWNnbJQohuDh LXDAHT0SApbqEje07gtqq9o14dSzRdOt3HvZCl1ftD+s7SiEn5AxMJvelOUcHtBcy47a wQTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=a4LS3sCS; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id w13si14789902pgr.362.2022.02.09.02.51.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 02:51:45 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=a4LS3sCS; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 013F7E040CA3; Wed, 9 Feb 2022 01:27:42 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382988AbiBGLVW (ORCPT + 99 others); Mon, 7 Feb 2022 06:21:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378740AbiBGLPz (ORCPT ); Mon, 7 Feb 2022 06:15:55 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D202BC0401CC; Mon, 7 Feb 2022 03:15:47 -0800 (PST) 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 8C1B1B811BC; Mon, 7 Feb 2022 11:15:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C41BBC004E1; Mon, 7 Feb 2022 11:15:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644232545; bh=ejKlmfkdpK4QC6TWW8BDeFyg6WR3o5WxoJii4FF16nM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a4LS3sCSMQqTNnj2xmfpAR4hb521ewztBvjBWi27TthU3PXDFdLmOCSYvIhvYG+qa 83mXwLmg8RqczKeX3fX6ryyM8LZAw9KKzjLw+AtVZi+O/PoD/EtXDQlox2wn5QHdiV ZbSe87SdAnbe5WPDhQImCoX61B/S8sVwUdlkIMVI= 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 4.19 44/86] ipv4: raw: lock the socket in raw_bind() Date: Mon, 7 Feb 2022 12:06:07 +0100 Message-Id: <20220207103758.989908777@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220207103757.550973048@linuxfoundation.org> References: <20220207103757.550973048@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 21800979ed621..8cae691c3c9f4 100644 --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c @@ -725,6 +725,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; @@ -744,7 +745,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