Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2199961rdb; Tue, 20 Feb 2024 23:18:54 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU0YgpgEwOIq437bDFCAwJNeMjm9bkxPcR4OcfaGV7IFVOzp+xrEVcIhEgJxPHhfUn4Hq1vduCUi6pcne6emuGfyE+KjXWyukhLKu1WdQ== X-Google-Smtp-Source: AGHT+IH4YRFzNSiDSg88uXglji/fzHI+4zSEFUdRk7Aj/sDEPTg3qkTwcwZ2defWltLVVigx6xtw X-Received: by 2002:aa7:d4d3:0:b0:564:1c4e:eb5c with SMTP id t19-20020aa7d4d3000000b005641c4eeb5cmr6812848edr.24.1708499934054; Tue, 20 Feb 2024 23:18:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708499934; cv=pass; d=google.com; s=arc-20160816; b=r1Xf4Nqsv//9/9OQis8uV3AQ8lq+OvALTi4EeWCKPOZuj04QuZuMAVPt+exZh+pKeI OdsNSmg41BGBNXPZ/Ub7xrhu4UCUvLUF7rcFubrojDNpKgtsb1pZXTk642t+hXCv4Oht MYvYNy5ZHqS9P5Kp2tF2lFu74xB9RJ+d7gPLhetlPBGa8l5bIwc94lkCYkWAlP2g4/eL h7osgYsICZVudTASdSGo/F1eVrFPEN6MzPXwvZSccD/1G9VMxrQo34QAKBU95ocZdiUt +BwW4lwdpyyoVNFeHyMIvh+jNE12nXj8SNDgHDXPGTMurZrIib8uxFKKa3b7X55QrISc qKNw== 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:subject:references:in-reply-to :message-id:cc:to:from:date:dkim-signature; bh=vh6UXdERl+gUl9cBq4S+KjIngsWFhxQy1ohOrIZDnMw=; fh=OoL3/w1FvRHyKLrvyvGkWGpBAVrLdh3452KT8J5gzLo=; b=aOdSMNvuS30pzEMJV2aQkcCiwRuHxQdM5wFc2gSZrVYuAnuH1e8vXnERhm6YdYr5ME 8/dQySHEQgefl0ZPzFv2gygwlaoJBIU3/sCrr/u6QkCcaduq7kRPcgffttU9E+u8ybc7 LizulhCPfgk8H/sJeNtPMP6jDOKCi9lE5oUT5/wqoaVn7HwACOFP7d8vKtNkudxl0asX 6cXzztV/t7JYwtrCG4H0/RlvqQGQAuh9Ph7l4sf0UwdGsfLorqBI2XxaOVGRq3MTNAb+ gj6R++o8MDrzKHjq4+4xGDLh9jJSZDEZQ1jmgt9UtJDq3kWdvr0DAduOyHxSScifsdjL bJew==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BiASDH47; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-74204-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74204-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id z2-20020a05640235c200b005647dac5fbbsi2519066edc.375.2024.02.20.23.18.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 23:18:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74204-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BiASDH47; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-74204-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74204-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 am.mirrors.kernel.org (Postfix) with ESMTPS id AF9A61F276A2 for ; Wed, 21 Feb 2024 07:18:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0772F3A8EB; Wed, 21 Feb 2024 07:18:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BiASDH47" Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (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 B85E839879; Wed, 21 Feb 2024 07:18:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708499920; cv=none; b=BNluWrTr6iGYKx/MuDGBrgYP1Pn3rHBa/soKfF/sOpV7b09QOfZrZVOmKgvUxs7SmCKucyncl3zkdarIzwCuxT9C77Q0TpsoeX9d8x2wQQ/qaG9qtqhAWwVpMVv6p8RW/cfta44bDtSoeD7xmBlTqBFev/ZAccZJt3ZuSyLf81U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708499920; c=relaxed/simple; bh=X6Cq+RW0HDSyeBS3C6pwEfX3WHpgDSCQAseO5Swl1dA=; h=Date:From:To:Cc:Message-ID:In-Reply-To:References:Subject: Mime-Version:Content-Type; b=cKXtc9df4/lH1FAL6k/+Vqdiqu5IzIP9Y/R7s9jGBK4BMQCC0GywAcW61ljkZD4Ls61Lp7dyA5DuYH44IqZqp2qXm0bW5rMoAkKnATkH7S7OSWrE07ugoqdZBM9FFyaWU29Yit3CQ6RGMh3YsbvxJ5R1jgamDm9Adtxpmgg5CLA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BiASDH47; arc=none smtp.client-ip=209.85.210.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-6e486abf3a5so702023b3a.0; Tue, 20 Feb 2024 23:18:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708499918; x=1709104718; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=vh6UXdERl+gUl9cBq4S+KjIngsWFhxQy1ohOrIZDnMw=; b=BiASDH47jvZkJ0z52bxcHNEpXdseRGf2OkI4M/G9EnDKIjEWrXtaRd+NWijJNpBmxf x5BHcRRzmwPq/dzRmhWb8tv5iVTkWiMdJA1S2nrp1fBPyp6mVN0rKnb8skO0P7IM3dru wPIOWqEKypah3dx7hckfQLwFH4KloObmXI69q6OHG+BVyk2Gy5094pDBX3qnx5B2x4cc oMR6UT5wD9Uz9SiRKH48eLuMqsHeVaqUYO3dB8a3QgsTraL5+brTitI+8iTiml1+80O9 6hbYVqXPJBEv6oIR0SBzpGyrDImpEQMsglAXxh26N9FJ89mnlCOd0qB96ixHdZMc6aTL kNQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708499918; x=1709104718; h=content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=vh6UXdERl+gUl9cBq4S+KjIngsWFhxQy1ohOrIZDnMw=; b=kZaEhT01vhKL/0O5nJSs/QxEdaupsUO/r71TfBgTuLQnpbH9Cs6lURWpD93QAG1Ss/ Q9nsGEinN0k5wVAOInWq9TzZcr6fTLg5kmUbDNbufCGymFL4TggTIh6VvSk8VGPoxcMe hLbMTlOtWirNPPZO7yfAuL1zg5bHUrZOJJ2i/bvBV2mP6NI2OIsmZoxcCNrkfTmD9jC+ +AmpGWprY/cj58ksr0uPIs3ioa0lc3remohP+pq7RJXA3qsnTL1n89I1l2pfJry7csBz dxJ2JGum3jlLrBU3DaSBXG/XLl/AAo7TJLjiAAWhT3za/gmITWFcL3Fc41MBPb5wi4X8 xkLg== X-Forwarded-Encrypted: i=1; AJvYcCWoG+TC0zSXXWDilnVmKZhwkTEZgi3U0gRKaNFim8MHF+3F1CK6gjFGtxD18ynQKIXCpxnnwcdROg4EkmLWolVE3hQ10EetEk7injq0L+SnH7jCaA2iwa5HmfrS95ORGaf2v4RnFAAyI2L0AdvvXMkQjT4adpnAhg2n X-Gm-Message-State: AOJu0Yz3NKJsDDzKchmB58HMV9p6WzBpr16D6k1tKSBFyA9XKcnWo0ui +xVOWEj+j5mh5HIy1mYB6G+LqYhTjOO4NdtDM4bFgcgm4PfKkfUr X-Received: by 2002:a05:6a00:2d89:b0:6e4:8d1d:7770 with SMTP id fb9-20020a056a002d8900b006e48d1d7770mr1622981pfb.3.1708499917882; Tue, 20 Feb 2024 23:18:37 -0800 (PST) Received: from localhost ([98.97.113.214]) by smtp.gmail.com with ESMTPSA id v2-20020a62a502000000b006e4362d0d8csm6156788pfm.36.2024.02.20.23.18.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 23:18:36 -0800 (PST) Date: Tue, 20 Feb 2024 23:18:35 -0800 From: John Fastabend To: Shigeru Yoshida , john.fastabend@gmail.com, jakub@cloudflare.com Cc: davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Shigeru Yoshida , syzbot+fd7b34375c1c8ce29c93@syzkaller.appspotmail.com Message-ID: <65d5a3cbac150_5fc5920879@john.notmuch> In-Reply-To: <20240218150933.6004-1-syoshida@redhat.com> References: <20240218150933.6004-1-syoshida@redhat.com> Subject: RE: [PATCH bpf] bpf, sockmap: Fix NULL pointer dereference in sk_psock_verdict_data_ready() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Shigeru Yoshida wrote: > syzbot reported the following NULL pointer dereference issue [1]: > > BUG: kernel NULL pointer dereference, address: 0000000000000000 > ... > RIP: 0010:0x0 > ... > Call Trace: > > sk_psock_verdict_data_ready+0x232/0x340 net/core/skmsg.c:1230 > unix_stream_sendmsg+0x9b4/0x1230 net/unix/af_unix.c:2293 > sock_sendmsg_nosec net/socket.c:730 [inline] > __sock_sendmsg+0x221/0x270 net/socket.c:745 > ____sys_sendmsg+0x525/0x7d0 net/socket.c:2584 > ___sys_sendmsg net/socket.c:2638 [inline] > __sys_sendmsg+0x2b0/0x3a0 net/socket.c:2667 > do_syscall_64+0xf9/0x240 > entry_SYSCALL_64_after_hwframe+0x6f/0x77 > > If sk_psock_verdict_data_ready() and sk_psock_stop_verdict() are called > concurrently, psock->saved_data_ready can be NULL, causing the above issue. > > This patch fixes this issue by calling the appropriate data ready function > using the sk_psock_data_ready() helper and protecting it from concurrency > with sk->sk_callback_lock. > > Fixes: 6df7f764cd3c ("bpf, sockmap: Wake up polling after data copy") > Reported-and-tested-by: syzbot+fd7b34375c1c8ce29c93@syzkaller.appspotmail.com > Closes: https://syzkaller.appspot.com/bug?extid=fd7b34375c1c8ce29c93 [1] > Signed-off-by: Shigeru Yoshida > --- By ensuring order of ops on teardown we should never have a loop here. Also this aligns with strp usage that also uses sk_callback_lock. Thanks. I suspect we haven't seen it because when this is being used we never remove socks from the map before the socket is released. Acked-by: John Fastabend > net/core/skmsg.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/net/core/skmsg.c b/net/core/skmsg.c > index 93ecfceac1bc..4d75ef9d24bf 100644 > --- a/net/core/skmsg.c > +++ b/net/core/skmsg.c > @@ -1226,8 +1226,11 @@ static void sk_psock_verdict_data_ready(struct sock *sk) > > rcu_read_lock(); > psock = sk_psock(sk); > - if (psock) > - psock->saved_data_ready(sk); > + if (psock) { > + read_lock_bh(&sk->sk_callback_lock); > + sk_psock_data_ready(sk, psock); > + read_unlock_bh(&sk->sk_callback_lock); > + } > rcu_read_unlock(); > } > } > -- > 2.43.0 >