From patchwork Sun Sep 3 15:21:52 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: 13373278 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A74EEC83F2C for ; Sun, 3 Sep 2023 15:22:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231415AbjICPWB (ORCPT ); Sun, 3 Sep 2023 11:22:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229970AbjICPWB (ORCPT ); Sun, 3 Sep 2023 11:22:01 -0400 Received: from tarta.nabijaczleweli.xyz (tarta.nabijaczleweli.xyz [139.28.40.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67491F1 for ; Sun, 3 Sep 2023 08:21:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202305; t=1693754513; bh=QMeZnV04dYfGiix7AosDHMUI3cZ6F+Vt4zBwig3niN8=; h=Date:From:To:Subject:From; b=pqk2GZEup8UyGYH4bRlbMqRp3WPaCkgJuGPQvF5Dl4HnYBgyAGsVLbFkKOh6vJgCO pYTH6NRwziCvGqyq9gavF9AJHC1LqjQJ5PKyJrg7RvfKO7X0KAmnqWOpCLTNo42RCv jjHUNvHfenTsGV2AJXidnAhkESqTrIymeoTq0teKrQ56CF7WexCUeccepUyWfrk+ul MY/w/+phxl9YrnQiMmvpoFjNcmbwv2VzNWcYvm8F2OVV3u8NjfD9e/+NVl59T0poXt P67oMmsfEOvJ0sRcU9+UyEnqFYmJBELLspJL7UJZSZLjtBiCOp+okBeloVgQdqwOlo yXmU4rMOcF0GQ== Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id 9B989B434 for ; Sun, 3 Sep 2023 17:21:53 +0200 (CEST) Date: Sun, 3 Sep 2023 17:21:52 +0200 From: Ahelenia =?utf-8?q?Ziemia=C5=84ska?= To: linux-nfs@vger.kernel.org Subject: [PATCH nfs-utils 1/2] fsidd: call anonymous sockets by their name only, don't fill with NULs to 108 bytes Message-ID: <04f3fe71defa757d518468f04f08334a5d0dfbb9.1693754442.git.nabijaczleweli@nabijaczleweli.xyz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20230517 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org 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 --- support/reexport/fsidd.c | 8 +++++--- support/reexport/reexport.c | 7 +++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/support/reexport/fsidd.c b/support/reexport/fsidd.c index d4b245e8..4c377415 100644 --- a/support/reexport/fsidd.c +++ b/support/reexport/fsidd.c @@ -171,10 +171,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] == '@') + socklen_t 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); @@ -183,7 +185,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 d9a700af..b7ee6f46 100644 --- a/support/reexport/reexport.c +++ b/support/reexport/reexport.c @@ -40,9 +40,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] == '@') + socklen_t 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) { @@ -50,7 +53,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; From patchwork Sun Sep 3 15:22:55 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: 13373279 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20061C83F2D for ; Sun, 3 Sep 2023 15:23:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232142AbjICPXB (ORCPT ); Sun, 3 Sep 2023 11:23:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229970AbjICPXB (ORCPT ); Sun, 3 Sep 2023 11:23:01 -0400 Received: from tarta.nabijaczleweli.xyz (tarta.nabijaczleweli.xyz [139.28.40.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56596F1 for ; Sun, 3 Sep 2023 08:22:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202305; t=1693754577; bh=sxo5ccr1lY+PT2swNH9zD9KjzRy2UjHSRv9Vo0OLvIM=; h=Date:From:To:Subject:References:In-Reply-To:From; b=FK4Yus8OQ9k/2XyxDi+3Jn0+TqJQirritZxV3fJHjKoSi/6ZM0ApwzVGyThKlcq40 yfVVoeciYldI1qBBu1MccMd5ZE+Qj6PElvyLVQCivM0Ai8b6QWll2ZUxmGKZZLcIm4 j9EFKhIKaPTV/FkOZhNG8fVmvpmMtD2P4qCVrhqa1Ejcla+8UMqrV4STzowGJj06i8 v6ZfWswBQ1kO68d+c7sAuYUG4vgQejw6MrP4NZv3r8Frg/hZlInOsL/0+P+CIA5hOK xWVi/ZR1kokSbfE23ceS0vHzw30JcZ7enUlBlfnyHwBZH8MPrtBrcuSJlF578Vu/KZ /Q/i0h8ZGFDhg== Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id 08CB9B3B0 for ; Sun, 3 Sep 2023 17:22:57 +0200 (CEST) Date: Sun, 3 Sep 2023 17:22:55 +0200 From: Ahelenia =?utf-8?q?Ziemia=C5=84ska?= To: linux-nfs@vger.kernel.org Subject: [PATCH nfs-utils 2/2] testlk: format off_t as llong instead of ssize_t Message-ID: <44adec629186e220ee5d8fd936980ac4a33dc510.1693754442.git.nabijaczleweli@nabijaczleweli.xyz> References: <04f3fe71defa757d518468f04f08334a5d0dfbb9.1693754442.git.nabijaczleweli@nabijaczleweli.xyz> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <04f3fe71defa757d518468f04f08334a5d0dfbb9.1693754442.git.nabijaczleweli@nabijaczleweli.xyz> User-Agent: NeoMutt/20230517 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org This, naturally, produces a warning on x32 (and other ILP32 platforms with 64-bit off_t, presumably, but you need to ask for it explicitly there usually): gcc -DHAVE_CONFIG_H -I. -I../../support/include -D_GNU_SOURCE -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -g -O2 -ffile-prefix-map=/tmp/nfs-utils-2.6.3=. -specs=/usr/share/dpkg/pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -g -O2 -ffile-prefix-map=/tmp/nfs-utils-2.6.3=. -specs=/usr/share/dpkg/pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -c -o testlk-testlk.o `test -f 'testlk.c' || echo './'`testlk.c testlk.c: In function ‘main’: testlk.c:84:66: warning: format ‘%zd’ expects argument of type ‘signed size_t’, but argument 4 has type ‘__off_t’ {aka ‘long long int’} [-Wformat=] 84 | printf("%s: conflicting lock by %d on (%zd;%zd)\n", | ~~^ | | | int | %lld 85 | fname, fl.l_pid, fl.l_start, fl.l_len); | ~~~~~~~~~~ | | | __off_t {aka long long int} testlk.c:84:70: warning: format ‘%zd’ expects argument of type ‘signed size_t’, but argument 5 has type ‘__off_t’ {aka ‘long long int’} [-Wformat=] 84 | printf("%s: conflicting lock by %d on (%zd;%zd)\n", | ~~^ | | | int | %lld 85 | fname, fl.l_pid, fl.l_start, fl.l_len); | ~~~~~~~~ | | | __off_t {aka long long int} Upcast to long long, doesn't really matter. It does, of course, raise the question of whether other bits of nfs-utils do something equally broken that just isn't caught by the format validator. Signed-off-by: Ahelenia Ziemiańska --- tools/locktest/testlk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/locktest/testlk.c b/tools/locktest/testlk.c index ea51f788..c9bd6bac 100644 --- a/tools/locktest/testlk.c +++ b/tools/locktest/testlk.c @@ -81,8 +81,8 @@ main(int argc, char **argv) if (fl.l_type == F_UNLCK) { printf("%s: no conflicting lock\n", fname); } else { - printf("%s: conflicting lock by %d on (%zd;%zd)\n", - fname, fl.l_pid, fl.l_start, fl.l_len); + printf("%s: conflicting lock by %d on (%lld;%lld)\n", + fname, fl.l_pid, (long long)fl.l_start, (long long)fl.l_len); } return 0; }