🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #9479

[PATCH bpf v2 01/15] bpf, sockmap: Write sg.start when recvmsg() faults

#9479
From: Alexei Starovoitov
Date: Mon, 02 Nov 2026 07:20
41 lines
12798 bytes
From: Josef Bacik <josef@toxicpanda.com>

__sk_msg_recvmsg() copies an sk_msg to the user buffer and starts at
sg.start. After a full copy of an element it calls put_page(), unless an
skb owns the page. It handles 0 copied bytes as a fault. It writes the new
sg.start after the loop, but not when copy_page_to_iter() faults.

  element    0: length 0, put_page()   1: fault here   2: not copied
  sg.start   ^ today                   ^ this patch

Each subsequent call copies 0 bytes from element 0 and returns -EFAULT. The
user cannot read the rest of the data. sk_msg_free() starts at sg.start
too. It calls put_page() for element 0 again and can free a page in use.

Write sg.start in the fault path too. The commit in the Fixes tag removed
this write. Do not write it for MSG_PEEK, which changes no element.

Fixes: c9c89dcd872e ("bpf, sockmap: Fix partial copy_page_to_iter so progress can still be made")
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---
 net/core/skmsg.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/core/skmsg.c b/net/core/skmsg.c
index df385a5a961e..f03519468ad1 100644
--- a/net/core/skmsg.c
+++ b/net/core/skmsg.c
@@ -443,6 +443,9 @@ int __sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg
 			if (copy)
 				copy = copy_page_to_iter(page, sge->offset, copy, iter);
 			if (!copy) {
+				/* The elements in front of i are used up */
+				if (!peek)
+					msg_rx->sg.start = i;
 				copied = copied ? copied : -EFAULT;
 				goto out;
 			}
-- 
2.55.0
Technical Details
Message-ID: <20261102072112.4160195-2-alexei.starovoitov@gmail.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354477-linux-kernel-netdev=dewy.ru
References: <20261102072112.4160195-1-alexei.starovoitov@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354477-linux-kernel-netdev=dewy.ru
From: alexei.starovoitov@gmail.com (Alexei Starovoitov)
Newsgroups: linux.kernel.netdev
Subject: [PATCH bpf v2 01/15] bpf, sockmap: Write sg.start when recvmsg() faults
Date: Mon,  2 Nov 2026 07:20:58 +0000
Organization: Usenet Network
Message-ID: <20261102072112.4160195-2-alexei.starovoitov@gmail.com>
References: <20261102072112.4160195-1-alexei.starovoitov@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2869349"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:qYYVd3ysqO1DLlKvYZ3zdvlm6B4= sha256:90LSv36sT5l7jzmtrCC6e1hAnpue0miki+fEbEQwFhE=
	sha1:PETud66iI0XaAkPSnStDdQ7tsew= sha256:/DPVzhI/xhtWW9L1e1AZ3+s7fFPi5tdZvPbanTETJqg=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 8E94A125CC7; Mon,  2 Nov 2026 10:21:55 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.048
X-Spam-Status: No, score=-3.048 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id cAcnLKW2NrJt;
	Mon,  2 Nov 2026 10:21:53 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-354477-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id F3C76125CC6; Mon,  2 Nov 2026 10:21:44 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 10AAD2CADD; Mon,  2 Nov 2026 07:21:28 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1793604085;
	b=t0D5c1vZea/tRAOS7jdiKdiU+V903olBXLVoMdBXjQMxFem6CrKBAKpghJykZs3pUQ+a
	 iCUbDAgEhrjx+CnP+acYeN7r5SzCLrHRxvyaX4iecmf4bjLm7188l1BFOUcA6KJcp/QDY
	 bnq1GX67uxLkGIFhsRdf10IFcsmMffpMMr68i+NDp1k7JP+8NJMt6CJmTkSEByDuwkCma
	 Co9/ocFbQr+HbBPR1LM5M/0SkotRZ8gtDDFFe3KagHrvNLxRKGXpItvuMvHX5/6Kc86L/
	 ybWniAAtDvHBCLPrG1Ga8cAjbbRP4PrWspRLW5B97SCXJ6Cw11Ysv7cHCLgjRb9R6pw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793604085;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
	 X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:Date:Message-ID:
	 X-Mailer:In-Reply-To:References:X-Mailing-List:List-Id:List-Post:
	 List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
	 MIME-Version:Content-Transfer-Encoding;
	bh=DFLLbX6mAbQ0jCV7LiEZmOooBbXiKj6J/ISxTH/9yE0=;
	b=MRyMgqUbXJ9FKKfs35dWqkbgKGTWJ574GyC9etsRnUA4ewxHsRogwWScyjNCQOz2qVPO
	 Uj6nxPgrsEloLfdpr03yKV43WqId0IXshf9Vt8EP4BQ2sEI5acEAKIH9IvGBxb+naD7nS
	 8u+h0yOoAeBLK8MNv/R/0Bp5jE/Aohr8vh/SLuHDru9gRX7saknwzDHHMVlTH4yxbismc
	 XA0I79ECwRBfKMqL6X8CCY00z6mC6JEcRSwtmwEQ/KC+asEgCqAW1OQmUjth2rkfi09W1
	 sEm7Ikl0eQN2ONl3Qj6RNMqSnRpiWzHNXo9bTcRQ1UwTPh+ltVtWZ0ct6P5FDinnXVw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=eJSyx7TR;
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 9D677606A331;
	Mon,  2 Nov 2026 07:21:25 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=eJSyx7TR
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.50
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793604084;
	b=AeYy+QzNR2vgpGad/DhiQnB4mjRz36ds+81UpKsxC+if5j+x4jMmJKu5fbT1OhgOEoM6
	 +zpEDKYPM8p5giesT8ZHYqI7M17jSljOt+j411XrNM4P3nlfWZtZo3qf97i21q+C/A4Vf
	 m5NCstpR16O+jkTmHuu2fm9gfyH+RnrxgiuQC5HkazrUsdP2uVEf3Pieeq+2TPafmNyCr
	 mIGHkuAXuu76uQvrYqRpDZKQ+Ei9bpumeK9UmuHnvUK87BQ6RzUexKBMY55nlDh/XvAdZ
	 wMOHsVOtuCetEDluieKbdcBloNuWBjUbzCW+oq8e+bbcw6DysICeoFdePF97IeTD0Ew==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793604084;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
	 From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:
	 MIME-Version:Content-Transfer-Encoding;
	bh=DFLLbX6mAbQ0jCV7LiEZmOooBbXiKj6J/ISxTH/9yE0=;
	b=urkHE89VMrVNIHi0fvD++shEwVcggTb+j0TWK1zfZNkp7lMNSHL84VDjRnwoOmOQcc95
	 H49AV4ODxP9q0D7SoU18URdjc58wdudBk+UTyjakX4oaAaNtZOfISdilRqGjuLLy7SEuM
	 bgtiYAKO6SQeFaX7ZRNDljWE7ot5YUgkBL2gICoWRz860qKsg2UR+K8Oj6c4ZQTQNgucW
	 lv+ECOuv8ozqsBmcK85HanNp3/S51TJASesIy4NKdQWKnjmlm8qCXa0AtRuvbA1Tddo6C
	 xOFGSIx2NQ9E07p7NUYVJtcZkJ/smx9YNBM11FxupVoaccztIncUfyEKHBQLoMRxOTg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=eJSyx7TR;
	arc=none smtp.remote-ip=209.85.216.50
X-Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 661E9606A326
	for <netdev@vger.kernel.org>; Mon,  2 Nov 2026 07:21:24 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 661E9606A326
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-3ab752f6244so3226447a91.2
        for <netdev@vger.kernel.org>; Sun, 01 Nov 2026 23:21:24 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1793604084; x=1794208884; darn=vger.kernel.org;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:from:to:cc:subject:date
         :message-id:reply-to:content-type;
        bh=DFLLbX6mAbQ0jCV7LiEZmOooBbXiKj6J/ISxTH/9yE0=;
        b=eJSyx7TRNJ+iKyP0JOkLH3MqYgNU8rRheJ7RoNPil0uheKPeT3rFg7jDgqGDxqARI8
         NUc79/B8R/5mXmaOrdUBb+JMbawAycIXZPV/MjQ8cZetEddKzKIc8+D9GUi+xnloWq/j
         GGudAmMviC6J3XieznA3NFiheP9KeBICvW2kPk8EeddVv3XmwA/26DtzEIttvJVVLV4m
         3hRQGqOmd4iIZ8wManSIGzvo+gQ0IcqJtf/KsmkC/y0v3GRqppCD64IaJYnMviSzGUDG
         mZXXRz6VwhZOX9ziK65RMhucePYFGaus8dd1qtXtsgmbOTyrkXhf9zCNhrDu4u6tCuoX
         uC+Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1793604084; x=1794208884;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from
         :to:cc:subject:date:message-id:reply-to:content-type;
        bh=DFLLbX6mAbQ0jCV7LiEZmOooBbXiKj6J/ISxTH/9yE0=;
        b=BJISlnykYkzFtpu+NOxcBwFycfCA0bbIUlfrX5KzKYV7q6bjL/E2bwYgW6+SMRqFsJ
         yp1pw7rj6G5+NU+h+uSrGgzgCe8LqIayDxbd+b5L/1RIWKJGWo2WHiocgiPd15EHPGtz
         27I2sZVJF/vj8IahI4p5fTU31XBVv6QH/WpGRqc0QU3rMdTvS3DgKLrmx5jqwBuI2TLh
         DYK2UD8kGeqCTWD9mBIic34+G9an0/FEEGYnYlm7pp/oVUz2mgxE1TsmerQkZWylQQgU
         sSR83cOPDFWLdvIUeOXwiL1bZ7w0ZR26JOrnIacAPi6Z/+uNntTy4yPeF2er7CfVm5ev
         i6Ow==
X-Forwarded-Encrypted: i=1; AKwUvBzke5JGY//7SRzMQstXsCj8LD6DjuZ1Gsfgz5WiXqMXPdrhogzhSf4YmKI+npTFmeHZrwXFMig=@vger.kernel.org
X-Gm-Message-State: APuU4Z8RJcNUZu4b4bCCBg3cE4tdeGWYQoh4UWAk0i2jqy2TPll8ewzu
	AC00dESr5RkNU8kMBIv4DxX2+4c41TVkLFzDMarh9FLoUyE2u3qwjnbV
X-Gm-Gg: AYBFou0jmm1pqaF2vj8VFXiog98pT0WLqH5Ao1shH3LRGxTC5/z5j5xoFSTwYoJPnC+
	7bRfZQpCvOad+Cav/9JFKxZ6hNhX+1GnmTFD7Ez6XG1A/tN/01naq4FbmVZlJBlx//ZIk2JLADH
	SvBbm+FzQy8YmMu/+STYKN2rC1FwRxoVTk6FE2WVN3Qi2n/s/k5nUSdHbmBq0L8+XZoSf66XnE6
	r1jX+mfZX0KeoFQiMvy1ZqRYWuGrOQOoVincNHyQussaBActQmAZOl2e3fPfldy/ciwnJnkFhuT
	LzlVsXLXjVG8tD3BcZFDRZcrAFkwnm3Q8ShkU7teXbHowD89DtgeXzDeJd2gX18+EJI0kyNosGw
	3LBnIhuYs7/uk1KC4I64X11go2umsUMz/IjKzXj0tNOSKDSBgO3sAljdqhnBphMa2YvKkyMoJ7e
	8AH99lCMwaqN9Cdh1/PG1MrReEPlmemrQ7qTNsCtEW34p5y9TkTo+G0AGOfpF8fOISvjQVUquUi
	OQyWqYHO1X6ivVNdMEP2Pt5nK/5U+8oRTUuGvFcviPI26nWKSTjqxRNww6taRUL6ZcjgOFnhG32
	Pdu86i1jRF8SyIYvwL8pVAbUxA5kaBw38GSXsgtGp0I9CXU61Q+HmbZaIh9v4dHmShbRYDZG0JV
	GMCBccQKns0o1KpKolTSFh/I9mK5EPotdEGnhizNumiAAm1n1xSFx49h4/h7I1KimmQ6sZBv70h
	U=
X-Received: by 2002:a17:90b:53ce:b0:3ad:6090:a190 with SMTP id 98e67ed59e1d1-3ae89817b01mr7725554a91.41.1793604083734;
        Sun, 01 Nov 2026 23:21:23 -0800 (PST)
X-Received: from coder-ast-ast-dev-ml-0.tail2dda0.ts.net ([153.61.198.248])
        by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3ae6e9426ffsm17877536a91.7.2026.11.01.23.21.22
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Sun, 01 Nov 2026 23:21:23 -0800 (PST)
X-Cc: daniel@iogearbox.net,
	andrii@kernel.org,
	eddyz87@gmail.com,
	memxor@gmail.com,
	john.fastabend@gmail.com,
	jakub@cloudflare.com,
	jiayuan.chen@linux.dev,
	davem@davemloft.net,
	edumazet@kernel.org,
	kuba@kernel.org,
	pabeni@redhat.com,
	horms@kernel.org,
	kuniyu@google.com,
	willemb@google.com,
	matttbe@kernel.org,
	mptcp@lists.linux.dev,
	mason@kernel.org,
	josef@toxicpanda.com
X-Mailer: git-send-email 2.55.0
X-In-Reply-To: <20261102072112.4160195-1-alexei.starovoitov@gmail.com>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list