Article View: linux.kernel.netdev
Article #10784Re: [PATCH net-next v4 2/7] net: cap sockopt_expand_out() at MAX_RW_COUNT
From: Jiayuan Chen
Date: Wed, 04 Nov 2026 04:15
Date: Wed, 04 Nov 2026 04:15
64 lines
10706 bytes
10706 bytes
On 11/3/26 7:01 PM, Breno Leitao wrote:
> sockopt_expand_out() grows the output iterator up to INT_MAX, but the
> MCAST_MSFILTER getters converted by the next two patches rewind it with
> iov_iter_revert() once they know the real reply size. iov_iter_revert()
> refuses to unroll past MAX_RW_COUNT:
>
> if (WARN_ON(unroll > MAX_RW_COUNT))
> return;
>
> MAX_RW_COUNT is INT_MAX rounded down to a page boundary, so a caller
> that expands into the (MAX_RW_COUNT, INT_MAX] range and then reverts
> hits that WARN_ON, and the iterator is left where it was instead of
> rewound. So does a caller whose optlen already covers such a size.
>
> Cap the size at MAX_RW_COUNT instead, before the early return for an
> optlen that already covers it, so a size that could never be reverted
> later is rejected up front.
>
> Sashiko found this while reviewing the conversions.
>
> Acked-by: Ido Schimmel <idosch@nvidia.com>
> Signed-off-by: Breno Leitao <leitao@debian.org>
Reviewed-by: Jiayuan Chen <jiayuan.chen@linux.dev>
> ---
> include/linux/net.h | 13 +++++++++----
> 1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/include/linux/net.h b/include/linux/net.h
> index e2a866fbcfa5ea..de56f89d475ee2 100644
> --- a/include/linux/net.h
> +++ b/include/linux/net.h
> @@ -80,16 +80,21 @@ static inline int sockopt_init_user(sockopt_t *opt, char __user *optval,
> *
> * Call it before writing through opt->iter_out: it re-anchors the iterator at
> * the head of optval. Only a user buffer can be longer than the optlen the
> - * caller declared, so a kernel-backed optval is refused with -EINVAL.
> + * caller declared, so a kernel-backed optval is refused with -EINVAL. So is a
> + * @size above MAX_RW_COUNT, which iov_iter_revert() could not unroll.
> */
> static inline int sockopt_expand_out(sockopt_t *opt, size_t size)
> {
> + /* iov_iter_revert() refuses to unroll past MAX_RW_COUNT, so a size
> + * beyond that could never be reverted back to the fixed part later,
> + * even when optlen already covers it.
> + */
> + if (size > MAX_RW_COUNT)
> + return -EINVAL;
> +
> if (size <= (size_t)opt->optlen)
> return 0;
>
> - if (size > INT_MAX)
> - return -EINVAL;
> -
> /* Re-anchoring reads iter_out.ubuf, so the iterator has to be a user
> * buffer that nothing has written through yet.
> */
>
Technical Details
Message-ID:
<bb64096f-2c73-428b-ac74-881227539a2f@linux.dev>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-356181-linux-kernel-netdev=dewy.ruReferences:
<20261103-sockopt_expand_out_v2-v4-0-2d36da923578@debian.org> <20261103-sockopt_expand_out_v2-v4-2-2d36da923578@debian.org>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-356181-linux-kernel-netdev=dewy.ru From: jiayuan.chen@linux.dev (Jiayuan Chen) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next v4 2/7] net: cap sockopt_expand_out() at MAX_RW_COUNT Date: Wed, 4 Nov 2026 12:15:51 +0800 Organization: Usenet Network Message-ID: <bb64096f-2c73-428b-ac74-881227539a2f@linux.dev> References: <20261103-sockopt_expand_out_v2-v4-0-2d36da923578@debian.org> <20261103-sockopt_expand_out_v2-v4-2-2d36da923578@debian.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="3323459"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:3X4WJxn+dbLEaJ966VqJkV4zptY= sha256:NVrK8f+9pSIJePuHH0FDW9342XYY0mb3idoBbLztWtU= sha1:gwo4r+51QP/BC7DC5Vx6ePexGd4= sha256:MmDBTw5YNOkLbgLXZXGtyzMgglNEUWAre+ofKpsVYnk= 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 E7E39112AD9; Wed, 4 Nov 2026 07:16:46 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -2.051 X-Spam-Status: No, score=-2.051 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, HEADER_FROM_DIFFERENT_DOMAINS=0.249, HK_RANDOM_FROM=1, 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 (1024-bit key) header.d=linux.dev 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 JSO0-oDwNDir; Wed, 4 Nov 2026 07:16:44 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-356181-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id D0FDE112ACA; Wed, 4 Nov 2026 07:16:35 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 2B52A2A970; Wed, 4 Nov 2026 04:16:19 +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=1793765778; b=hkGKr7QxiT9j69fWl4LdRP4hbIG/ZRhhYygRuN4BfZVIezuwpSDiNMqYztgVZ9ENw5r5 NlY4Pfp+81mlzfrKoPzZTNA++uy9zVhRHYApixxzKWvTAb9Ra1mkg5Q/eZKLq4n2TgtjA aIfP50dNBiniS8deRsUj/gcMYPIOahxJK/cC37iybvaS+JRd+l2wd+/CghQrA9S6gmYw5 JwBH/MYirfxvi1op8rOQPTx58aijkZACgjRtgstzEsq2qFoBjXuhaUxKOOAyujvKhMd/S 1mBgJJNoQOkCEMbaADlcNqUSxNTYZhhEgwglw0ejBkYMwfmnKtVE6hV/lnMm8tJB4vg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793765778; h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature: X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version:User-Agent: Subject:To:Cc:References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=K/cIC+iFmdevIAI+I2RKVd6I0g7XOiCzAkoSeW4/ahA=; b=BrXhoVIACsErZ4+o0sKPivK5416tdH+NWgAQbeSkAiU+kSydkdUD/Pkw/rjg/qhwekYk 0OcwQmAdq/zdSqzbPAa5KRQpytKq7waaCsPOlWVhtcAC9Z+c0IJFzWAI+jTCO6rJKN/zk Pzx9AAzuD72GgdnzFQsu4WgzsDQ3FfIiBkGRriOuRWDL8cKPjFqwpuvsZ4eCGhF2qv3qi LkVTk+kFL9lFV3kZ9Bz6wCoeVcnSIkjSipzeloodx1K5CK4iM1/bxl+rk4ZoqgBhxIr4G SBVZdw+lyH9FDTIT3Cn4n7+uuok/2dq5KUXsVAZeaRs3OURTT31SzNU7/LQcwiJ/MgQ== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=Z7CawluL; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; 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 A9109606A337; Wed, 4 Nov 2026 04:16:18 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=Z7CawluL X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.185 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793765777; b=K0lgPcQOkByUb6TuHyOhwJ4LNbwMyh3X5flLwSl5xQvkZhBPf6Iw4NM01zDFvd6uqi2K gOPv0RzJHAhbthq1rii3pNdOP4+MAnXdl6C9W3BfvIutydYu2OHeuxNaaGynJxG/6zxh6 uPLpfvoBI4+Td6Iu7gFNmQqukFJoCtv/eUe6iQPceqhplrzzZm03Uh2PAzK5FMiCVW9QO /YAr9Fh/U29ST7hB0CjI99E8PMbppWB1j2l2ynpgI5dLg+bR98cLPwtlfEtXZhWGVK4we 987svReBMkDpAW8IHZUrMPes2+ZkIOCWKtrvkqEBZX3OSLBWl2XeR1Jrz9DEj+ZQoWg== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793765777; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=K/cIC+iFmdevIAI+I2RKVd6I0g7XOiCzAkoSeW4/ahA=; b=ngvOPm6CFyvF/0SXDTn25DJTZdf5u1BuFFgNkDkqGfQgVcAemoD2XrDDA/C9hk9sX7In 7Ci+34jA70Q6cep4GWHgIDFzrJhhSSwqaEnisY47WHqptm9kuy82673MiuDcMgW3pk+5V V6CZNTN4kPsnz4A3aBirGPjv5pc2ss+Dn4E1k+CEw94vM+ydzV17ndDSzcGULWfajcRrT H9sAmTxGaBfbBCfH0uXw9vP0geVXGDf9C1OOEdKdFAhit/uL+KSEruSh2EGphMiHItow7 FO7CTeaOXhS2l21SU++iRh3tq7eA02E/vqzs3weHeMgFGiGYFwdxP+EyEbKAqKd7ciQ== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=Z7CawluL; arc=none smtp.remote-ip=95.215.58.185 X-Received: from mta1.migadu.com (out-185.mta1.migadu.com [95.215.58.185]) (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 06AFA606A328 for <netdev@vger.kernel.org>; Wed, 4 Nov 2026 04:16:16 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 06AFA606A328 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: netdev@vger.kernel.org X-DKIM-Signature: a=rsa-sha256; bh=vOi5qQ0/DXnG4QFkyblinf0P8GKtrfv4uQiJ8Uvnh54=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1793765774; v=1; x=1794370574; b=Z7CawluL2fAeDcWOMjTaSwZXO5rltRY3EmeRBJOdaLjKlQj/ClrRIakW7Ph6cMVOYJA2sH8H p6vmttNFNOJBb7jhf/TykWnsYTBhl1jKKBxnG6QQfb6oD3DtJYXkvfPLoCeYhJbejs/v8DBJbO9 gnw6axvo809dSLfQDnqs/1og= X-Envelope-To: netdev@vger.kernel.org X-Received: by smtp.migadu.com with ESMTPS id 5164afd9a38a0a63; Wed, 04 Nov 2026 04:16:14 +0000 X-Mizu-Trace-ID: 5164afd9a38a0a63 X-Migadu-Flow: FLOW_OUT 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 X-User-Agent: Mozilla Thunderbird X-Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, david.laight.linux@gmail.com, kernel-team@meta.com X-In-Reply-To: <20261103-sockopt_expand_out_v2-v4-2-2d36da923578@debian.org>