From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796512315; b=2/07kWlI/rMY1g3wNb8tjj3J0qqdjUZYjfyWsvzOg7ELYCp4pXTt6uyNpGYGjXmwf9cf KMD9i03NIsisHrgim8nyrl4Eqts3i8/Nc8k0M9dLSWfQ1piWsTaG6cN6rTeXB7MW7w4mz Yhgllc7/S88Imy9QcyqrURd3oz7nDte5H6JVMvcmwWDpz1mm5N8YXlbiWNQmAZEuGDnbu QOkc4MYRC4L0X8TZJDx841sWqtM7VCuXnCzVDkS7ehCH8xZzh9mkR4kVaTbcw5msEtqpM O3zNShQgZlovOKgjGMcc7wwjmeuTfdXLw3++p+XgZkTYdMBOnNtRU95D5dhi98DX7aw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796512315; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: 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=Kb8CSyjHLnztyUtAA80nKoMF9IU0/0DhMAEJZIu+JV4=; b=2aUs6R0/JohwwHYGa7Ti8Tl0ChXKn+xR/hLIJn0dwfUoZVcG6fWwW72Q8R0D1xo62M0Z FXOlXeak7QjDARpbqM9kKHDbk7w5B177AQjHvh/2yfu+gzE1EY4FFCbZ553mn87UgRDaf w9KMdiKigVMgkJ0plMX0wZG7HJIy6OukCFvC3WrWoP+ugz+CfaaFu3xWfd0Cro1QKU+IQ 6EC/JP7+QXFmoFxMcjJlBOjoywQbhrQTIZiE7uvTZzsJgBB7ez/WuNa8BAKrD0OviznQI PQqDhX16cJyOOllcDJyjqRyoCNMaBviImfk2fzoklyJbZ0TU9mtavCIJK4INX37hCVw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass header.d=kernel.dk header.i=@kernel.dk header.a=rsa-sha256 header.s=google header.b="HixK/eHu"; arc=none smtp.remote-ip=209.85.210.51 Received: from mail-ot1-f51.google.com (mail-ot1-f51.google.com [209.85.210.51]) (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 1C4E0606A31F for ; Sat, 5 Dec 2026 23:11:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1C4E0606A31F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.dk header.i=@kernel.dk header.a=rsa-sha256 header.s=google header.b=HixK/eHu Received: by mail-ot1-f51.google.com with SMTP id 46e09a7af769-8633b750a19so1170558a34.2 for ; Sat, 05 Dec 2026 15:11:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.dk; s=google; t=1796512314; x=1797117114; 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=Kb8CSyjHLnztyUtAA80nKoMF9IU0/0DhMAEJZIu+JV4=; b=HixK/eHuQyU4TH9uO6e689H2A7rimHe7RBNnHm66fqHiGUBMlX2xqwRMDDzcoJEj1L VezCz31T/R097nzXCNQVFVsQ5NXS6IyJVst24PfQ41yHTigX2dU7BYZ/nMvrGw/WaTgD suN5hHK7jI+6wkcgQiCJrtiCy5/BRuX7tDsVuJH4XZQf7uohevUZDWQJqgu94p4t6uVL jM4KyHZpkiWOXFnFZliAZyaPXwUYp11SmiqiXUG29I3LbL/qLpuUZ+PN8lSB8saWebTg gibT7hDZMh0b1EuV+xXqXIKx8iq91gpzscdoed+roai8j7bsBLRZu/oFdxLK4YurL8eT vqDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796512314; x=1797117114; 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=Kb8CSyjHLnztyUtAA80nKoMF9IU0/0DhMAEJZIu+JV4=; b=HoGSOP90ldpY+gFQaf6V7qSwzM8vgKnuzdhnMW3JVQEWWAZMumB2dmgvCGxxbnvnK2 uUu3mgPYY5IiCFfM+4uOmrd+hXrt6SFMLO5tDlM/qnOa1Xb6NJhQZzzzkqQbXn/wIlsl 8UkxH44waF7x5hCV9stIDzvbs3GEiLKFtGipbb4dtE8L54ZwkkzWiDEu/IN6xOu/NbrD 8TmLZMaNhAs8qR8FwYHrciY0wkNaMoZ/OZOHJO9CLlgR5pd/v7wm/87OAtRxB2/tE7Gp g8Fyhr8PGUheKGY0/U1XPbklI2HRJpZW1zXNxjcTkgAeiKbrwNLmci2OXhwki+vaa9dx 0YbQ== X-Gm-Message-State: APuU4Z8czdFD+wk5DI2xx/GaG14JKb2ZY0mkO/hdTzPTidpIG/2lVxDh ovH4rlLPfg3AQFK5uz2n7NSm6hyk5oFoeKeOkz6ZvBNZVrniEZocYtPxB04S8GEOeX/VEVuzzAL XlWjZJQo= X-Gm-Gg: AZFdTZfnLbt0Aw1D8bywdJE54apNahe5jagpYTOcRUS1GCgJM9+CKBiW2aHYmXYzUeG +XqQFIf5JgakUp8K3akN8zgyDgFeiPJC7//Pc5L210S1uhGXh4P43qZhvOkgWHdDY4yPdTY4dsN lOCFvnV2xmMylX+kBUmgtXjFR9gQcMyBFSyM+uZmmMLHQWBfq+iWp54oD02c2BvqUZgXxWKfgH5 HZ8ll65OWlXdMnGzq7+iPKd7KS9A6Hk9uOxMZVbuMLb1jbzeTZakwXWiCpRXDn4N8IpyU/3mEVa lsEfn7xo945wQ1SVmwYiB5rhAawZ7G5WPQHFb2U02mbSSiUh2txYoY0TP6eJGo+3D4597LLrzUG Q6ewY/368srGvREDJLzUtKkLM99CBS022IdE1PSE9l0pnxvGiSq5UENn7u9LMopzSXN+GVaV+Au UjsxH3We316wVO2vIm+IEftJU7vtAyktRhtMOKkhV8VFKzUS86PNO4HDXFlJzYbQChKU7ZGQkF2 MLqGxUfZathfb6rDQPohqCco9AhxB+cBWwA/hIcUiUEg3N8iYc6GMHXmDbUyZvhViYqoekPRAFK jqFliK6Cp0iub4tBCNgvRjksQLr7ePFkYPKFvjF4h1mCO5z0LJ+8v+e277wmnTr6LnsLkAwp12x /TNJgLf8N2hpB9VzQ+9odgHdWBb6vok8RwSZM X-Received: by 2002:a05:6808:1496:b0:575:7930:e650 with SMTP id 5614622812f47-57f208b3253mr6317883b6e.54.1796512314187; Sat, 05 Dec 2026 15:11:54 -0800 (PST) Received: from r7625 ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57f1f6fe2ecsm4086916b6e.14.2026.12.05.15.11.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 15:11:52 -0800 (PST) From: Jens Axboe To: stable@vger.kernel.org Cc: io-uring@vger.kernel.org, gregkh@linuxfoundation.org Subject: [PATCH 6.18.y 02/14] io_uring/net: don't copy msg_name on a recvmsg retry Date: Sat, 5 Dec 2026 23:11:35 +0000 Message-ID: <20261205231147.4095031-3-axboe@kernel.dk> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261205231147.4095031-1-axboe@kernel.dk> References: <20261205231147.4095031-1-axboe@kernel.dk> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Chris Mason Commit bbdf19889585f036692a0c77a1402a37cf07c417 upstream. IORING_OP_RECVMSG with MSG_WAITALL can write past the end of the user's msg_name buffer, if a partial receive is retried and the source address is longer than the buffer. msg_namelen is an in/out field: move_addr_to_user() reads the size of the buffer from it, and then stores the untruncated length of the address there. So the size is valid for one call to ____sys_recvmsg() only. But io_recvmsg() passes the same umsg and uaddr again when it retries a partial receive, and nothing restores msg_namelen in between: msg_namelen = 16, AF_UNIX source address of 110 bytes size read bytes copied msg_namelen stored receive 1 16 16 110 receive 2 110 110 110 If the copy in the retry faults, the result of the request lacks the data that the retry took off the socket. A retry that hits EOF has no address, so it stores a msg_namelen of 0 while the buffer holds the address. And an address that is longer than the one before it is truncated to the length of the one before. The fix used here is to copy the address out with the first part of the data only, and to leave msg_name and msg_namelen alone in the retries. The address is now that of the first part of the data and no longer that of the last part. The two differ only if the source address changes within one request: on an unconnected SOCK_SEQPACKET socket that receives from several peers, or if an AF_UNIX peer binds between two parts. A program that passes a msg_namelen smaller than its buffer got the whole address from the second receive on, and now gets the truncated address, as from recvmsg(2). The retries also no longer reach audit_sockaddr(), so with an audit rule for IORING_OP_RECVMSG the event of the retry that completes the request can lack its SOCKADDR record. The event that keeps the record is that of the first partial receive, which audit logs as failed with -EAGAIN. Fixes: 7ba89d2af17a ("io_uring: ensure recv and recvmsg handle MSG_WAITALL correctly") Signed-off-by: Chris Mason Signed-off-by: Jens Axboe --- io_uring/net.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/io_uring/net.c b/io_uring/net.c index f9ec1e709ef8..fa70b07b73f8 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -1114,6 +1114,8 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags) if (ret > 0 && io_net_retry(sock, flags) && io_net_kbuf_can_retry(req, sel.buf_list, kmsg)) { sr->done_io += ret; + /* msg_name and msg_namelen are filled in, leave them */ + kmsg->uaddr = NULL; return io_net_kbuf_recyle(req, sel.buf_list, kmsg, ret); } if (ret == -ERESTARTSYS) -- 2.55.0