From patchwork Tue Nov 21 21:14:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?0L3QsNCx?= X-Patchwork-Id: 13463571 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nabijaczleweli.xyz header.i=@nabijaczleweli.xyz header.b="qtcKcdy9" Received: from tarta.nabijaczleweli.xyz (tarta.nabijaczleweli.xyz [139.28.40.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1AB79E for ; Tue, 21 Nov 2023 13:14:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202305; t=1700601288; bh=UY/QglsNzKErcVBfqS09kPdYvYOuojG/aj3LgOPNZ1Q=; h=Date:From:To:Subject:From; b=qtcKcdy998fQ2xvqCm2CBQtNBU07FzP3cVfPjgWtAxuQzzVZZ6FTGJf08cZzFnqBU LCtkdqBLlAKTJcVkPV+Quht0IKNBEIlt1M7g5/WMEbc/ravPqAgKHRlP9Vb+IoYSbh uP1Z6bJz8/o27SIm+c80NkCuFWUD5GlvuXlkq08+lEPU8NAI7IsVD/qcYSNBRCKBY1 QsyU6MwjlwgxNPhBO6tUb0hqB84dgxXsZ6iLti6rra8HM3IF13lf5N8/4KLvcTILdm ZS1T1HrmlGckkJQQNcJeYK69TIducs6AVoQnlZC85HYi+lrE3S3FGzncQ7CCNvGXeU fQDKKScPHEm2w== Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id 6070811FC6; Tue, 21 Nov 2023 22:14:48 +0100 (CET) Date: Tue, 21 Nov 2023 22:14:48 +0100 From: Ahelenia =?utf-8?q?Ziemia=C5=84ska?= To: linux-nfs@vger.kernel.org, NeilBrown , Steve Dickson Subject: [PATCH nfs-utils v2 1/2] fsidd: call anonymous sockets by their name only, don't fill with NULs to 108 bytes Message-ID: Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20231103 Since e00ab3c0616fe6d83ab0710d9e7d989c299088f7, ss -l looks like this: u_seq LISTEN 0 5 @/run/fsid.sock@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 26989379 * 0 with fsidd pushing all the addresses to 108 bytes wide, which is deeply egregious if you don't filter it out and recolumnate. This is because, naturally (unix(7)), "Null bytes in the name have no special significance": abstract addresses are binary blobs, but paths automatically terminate at the first NUL byte, since paths can't contain those. So just specify the correct address length when we're using the abstract domain: unix(7) recommends "offsetof(struct sockaddr_un, sun_path) + strlen(sun_path) + 1" for paths, but we don't want to include the terminating NUL, so it's just "offsetof(struct sockaddr_un, sun_path) + strlen(sun_path)". This brings the width back to order: -- >8 -- $ ss -la | grep @ u_str ESTAB 0 0 @45208536ec96909a/bus/systemd-timesyn/bus-api-timesync 18500238 * 18501249 u_str ESTAB 0 0 @fecc9657d2315eb7/bus/systemd-network/bus-api-network 18495452 * 18494406 u_seq LISTEN 0 5 @/run/fsid.sock 27168796 * 0 u_str ESTAB 0 0 @ac308f35f50797a2/bus/systemd-logind/system 19406 * 15153 u_str ESTAB 0 0 @b6606e0dfacbae75/bus/systemd/bus-api-system 18494353 * 18495334 u_str ESTAB 0 0 @5880653d215718a7/bus/systemd/bus-system 26930876 * 26930003 -- >8 -- Fixes: e00ab3c0616fe6d83ab0710d9e7d989c299088f7 ("fsidd: provide better default socket name.") Signed-off-by: Ahelenia ZiemiaƄska Reviewed-by: NeilBrown --- v1: <04f3fe71defa757d518468f04f08334a5d0dfbb9.1693754442.git.nabijaczleweli@nabijaczleweli.xyz> v2 NFC, addr_len declared at top of function support/reexport/fsidd.c | 9 ++++++--- support/reexport/reexport.c | 8 ++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/support/reexport/fsidd.c b/support/reexport/fsidd.c index 3e62b3fc..8a70b78f 100644 --- a/support/reexport/fsidd.c +++ b/support/reexport/fsidd.c @@ -147,6 +147,7 @@ int main(void) { struct event *srv_ev; struct sockaddr_un addr; + socklen_t addr_len; char *sock_file; int srv; @@ -161,10 +162,12 @@ int main(void) memset(&addr, 0, sizeof(struct sockaddr_un)); addr.sun_family = AF_UNIX; strncpy(addr.sun_path, sock_file, sizeof(addr.sun_path) - 1); - if (addr.sun_path[0] == '@') + addr_len = sizeof(struct sockaddr_un); + if (addr.sun_path[0] == '@') { /* "abstract" socket namespace */ + addr_len = offsetof(struct sockaddr_un, sun_path) + strlen(addr.sun_path); addr.sun_path[0] = 0; - else + } else unlink(sock_file); srv = socket(AF_UNIX, SOCK_SEQPACKET | SOCK_NONBLOCK, 0); @@ -173,7 +176,7 @@ int main(void) return 1; } - if (bind(srv, (const struct sockaddr *)&addr, sizeof(struct sockaddr_un)) == -1) { + if (bind(srv, (const struct sockaddr *)&addr, addr_len) == -1) { xlog(L_WARNING, "Unable to bind %s: %m\n", sock_file); return 1; } diff --git a/support/reexport/reexport.c b/support/reexport/reexport.c index 78516586..0fb49a46 100644 --- a/support/reexport/reexport.c +++ b/support/reexport/reexport.c @@ -21,6 +21,7 @@ static int fsidd_srv = -1; static bool connect_fsid_service(void) { struct sockaddr_un addr; + socklen_t addr_len; char *sock_file; int ret; int s; @@ -33,9 +34,12 @@ static bool connect_fsid_service(void) memset(&addr, 0, sizeof(struct sockaddr_un)); addr.sun_family = AF_UNIX; strncpy(addr.sun_path, sock_file, sizeof(addr.sun_path) - 1); - if (addr.sun_path[0] == '@') + addr_len = sizeof(struct sockaddr_un); + if (addr.sun_path[0] == '@') { /* "abstract" socket namespace */ + addr_len = offsetof(struct sockaddr_un, sun_path) + strlen(addr.sun_path); addr.sun_path[0] = 0; + } s = socket(AF_UNIX, SOCK_SEQPACKET, 0); if (s == -1) { @@ -43,7 +47,7 @@ static bool connect_fsid_service(void) return false; } - ret = connect(s, (const struct sockaddr *)&addr, sizeof(struct sockaddr_un)); + ret = connect(s, (const struct sockaddr *)&addr, addr_len); if (ret == -1) { xlog(L_WARNING, "Unable to connect %s: %m, is fsidd running?\n", sock_file); return false;