[PATCH v5 4/9] landlock/selftests: Test LANDLOCK_ACCESS_FS_RESOLVE_UNIX

Günther Noack gnoack3000 at gmail.com
Fri Feb 20 17:04:11 UTC 2026


On Fri, Feb 20, 2026 at 05:27:52PM +0100, Günther Noack wrote:
> On Wed, Feb 18, 2026 at 08:11:26PM +0100, Mickaël Salaün wrote:
> > On Sun, Feb 15, 2026 at 11:51:52AM +0100, Günther Noack wrote:
> > > --- a/tools/testing/selftests/landlock/fs_test.c
> > > +++ b/tools/testing/selftests/landlock/fs_test.c
> 
> > > +	strncpy(addr.sun_path, path, sizeof(addr.sun_path));
> > 
> > fs_test.c: In function ‘set_up_named_unix_server’:
> > fs_test.c:4125:9: error: ‘strncpy’ specified bound 108 equals destination size [-Werror=stringop-truncation]
> >  4125 |         strncpy(addr.sun_path, path, sizeof(addr.sun_path));
> >       |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > 
> > We should also ASSERT the result to make sure path's length is not too big.
> 
> Fair enough, will do, because it's less confusing.
> 
> (FWIW though, I think Linux can technically deal with a sun_path that
> does not end in a NUL byte. See the long comment in unix_mkname_bsd().
> But that's a Linux peculiarity.)

FYI, before the question comes up why I didn't use strscpy: We don't
have that library in these userspace tests, so it is now:

	struct sockaddr_un addr = {
        	.sun_family = AF_UNIX,
        };

	ASSERT_LT(strlen(path), sizeof(addr.sun_path));
	strncpy(addr.sun_path, path, sizeof(addr.sun_path)-1);

–Günther



More information about the Linux-security-module-archive mailing list