From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796380499; b=yf3cRJXwu/e8VrlwfqgjVZrg0L7SGNoFd3L+j6vuBwoHycpTiBIOUCTsAbURNnnOZ6ui PR9XuwkQ7QEyRd+geeU/6RSxaFAgCVF9piEySFSK64LjZqJyyx47gC9OMZqZu1VBed+mC xlbjefpewxwoi7eVCCbXecypnGuO8WDkw8SRmd5fm5vrugxBFQBTptuE95TuepuOAzC3+ 0A3gZRF1a3ifKvJDfeKbsR9MqGp96Kpjc2w2W4QmTIXyvHl0BCOoBhkGHoCbDgvsPsFoA hkFmm7bdA3GFyEWLjKCsMv0SUulOWAVHtYea/vOyZgaDm6fLL2uHvexwMlFn4RdQbAw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380499; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=YWgdJlOVS3+/wBAhQIsQwlrqwkWfGa7OAbmL2VuC0ew=; b=uO2kvaDJ7PskyM8McJvyLuYUOatFQP3ae/AaYbBN2FwJyPXaGzi/KaevUX62G4hYy8TR pBMEzNzeBRdZST67w4/OOoAY8LpDTOon9LEwagyTeVFjsZA92NbiXWXwT1Mt6vnBlo8XN tJjLF/Sae/dEro97Hd3rX9oOvrEc/WqPd8C7yd8lt8TkXmZXNLecRBVjsho+rIrTdsuo9 3pZB+NnX3Wm7k/ld/m5vSs9tNU48468xWzb6djOQAf1PgR8BkJfMOXnySQsmr4f9UKIgQ fw6013CaACNubrzAedjFy+89DeB7I4M6f3RaaigIBQLBZbb0ACq9C2X77OLA+9GI+FQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=lFJ3WDCj; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 55D6C606A680; Fri, 4 Dec 2026 10:34:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=lFJ3WDCj Received: by smtp.kernel.org (Postfix) with ESMTPSA id C40DE1F000CE; Fri, 4 Dec 2026 10:34:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380499; bh=YWgdJlOVS3+/wBAhQIsQwlrqwkWfGa7OAbmL2VuC0ew=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=lFJ3WDCjwd7DlWw1ATNnsNhUBzYgS26cQbMKL4FcE6kwq8Tm9m5foaKVR/6bNiL/L H2YPhdXL5pnpu77fTV1xhyXQOWHlhLD9ohrdkyT11dw0GItvU088vFVM6v7vbIxeIx Ll8M9ueEsIH8f/JWwuoQQO4iJhFLUKNseEfiiNHE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexei Starovoitov , Sasha Levin Subject: [PATCH 7.3 299/742] bpf: Clear family and port of a short address for cgroup sockaddr hooks Date: Fri, 4 Dec 2026 19:02:43 +0900 Message-ID: <20261204100642.981325843@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore 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 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexei Starovoitov [ Upstream commit 2abc088aae543fa97350df8b2dd5eedf622e380d ] recvmsg() from a unix socket that has no name leaves the buffer of the address as it is, and that is on the stack of the kernel. The program reads user_family and user_port whatever the length is. bpf_sock_addr_set_sun_path() sends the family to user space. Clear the bytes from the length up to 4. Write AF_UNIX next to the path in the kfunc. Fixes: 859051dd165e ("bpf: Implement cgroup sockaddr hooks for unix sockets") Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20261125032938.670542-42-alexei.starovoitov@gmail.com Signed-off-by: Sasha Levin --- kernel/bpf/cgroup.c | 4 ++++ net/core/filter.c | 1 + 2 files changed, 5 insertions(+) diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c index 7455d0b7d559c..c020cd11c279c 100644 --- a/kernel/bpf/cgroup.c +++ b/kernel/bpf/cgroup.c @@ -1787,6 +1787,10 @@ int __cgroup_bpf_run_filter_sock_addr(struct sock *sk, ctx.uaddrlen = 0; } else { ctx.uaddrlen = *uaddrlen; + /* Programs read the family and the port also of a short address. */ + if (ctx.uaddrlen < offsetofend(struct sockaddr_in, sin_port)) + memset((void *)uaddr + ctx.uaddrlen, 0, + offsetofend(struct sockaddr_in, sin_port) - ctx.uaddrlen); } cgrp = sock_cgroup_ptr(&sk->sk_cgrp_data); diff --git a/net/core/filter.c b/net/core/filter.c index 22246ec8f0c68..e5284b8345838 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -12617,6 +12617,7 @@ __bpf_kfunc int bpf_sock_addr_set_sun_path(struct bpf_sock_addr_kern *sa_kern, return -EINVAL; un = (struct sockaddr_un *)sa_kern->uaddr; + un->sun_family = AF_UNIX; memcpy(un->sun_path, sun_path, sun_path__sz); sa_kern->uaddrlen = offsetof(struct sockaddr_un, sun_path) + sun_path__sz; -- 2.53.0