NetBSD Problem Report #57313

From www@netbsd.org  Thu Mar 30 15:40:30 2023
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 1BA581A9239
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 30 Mar 2023 15:40:30 +0000 (UTC)
Message-Id: <20230330154028.85B751A923C@mollari.NetBSD.org>
Date: Thu, 30 Mar 2023 15:40:28 +0000 (UTC)
From: timo@math.uni-bonn.de
Reply-To: timo@math.uni-bonn.de
To: gnats-bugs@NetBSD.org
Subject: find(1) needlessly bails out if CWD cannot be opened
X-Send-Pr-Version: www-1.0

>Number:         57313
>Category:       bin
>Synopsis:       find(1) needlessly bails out if CWD cannot be opened
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Mar 30 15:45:00 +0000 2023
>Closed-Date:    Sat Aug 05 16:31:28 +0000 2023
>Last-Modified:  Sat Aug 05 16:31:28 +0000 2023
>Originator:     Timo Buhrmester
>Release:        8.2_STABLE
>Organization:
Math. Institute, Bonn University
>Environment:
NetBSD werra.math.uni-bonn.de 8.2_STABLE NetBSD 8.2_STABLE (MI-Server) #17: Fri Jul 16 14:01:03 CEST 2021  support@trave.math.uni-bonn.de:/var/work/obj-8/sys/arch/amd64/compile/miserv amd64
>Description:
There's cases where you can't find(1) for the sole reason of $CWD not being readable, even in cases where find has no business doing anything there to begin with.

$ pwd
/home/timo
$ sudo find /
find: .: Permission denied
$

The thing to note here is that /home/timo is mounted from a file server, local root is squashed to something non-root on the fileserver, therefore the local root cannot access /home/timo.

But looking at the invocation, there's no need to access /home/timo in the first place.

This is caused by find's main.c doing this:

if ((dotfd = open(".", O_RDONLY | O_CLOEXEC, 0)) == -1)
    err(1, ".");

which is behavior that was already present in 386BSD.

Looking at the source, "dotfd" seems only relevant for -exec and friends, so maybe a conditional to only do that if an -exec, -ok, etc has actually been specified might be a possible solution.
>How-To-Repeat:
To avoid the whole NFS setup, the following steps will also reproduce the behavior:

(don't be root)

$ mkdir foo
$ cd foo
$ chmod 000 .
$ find /


>Fix:
find should bail out only for situations where the ability to access "." is actually required later on.   It might stand to debate, whether find should care at all.  It might as well just execute the -exec part and let the exec'ed program deal with the fact that it can't access it's own CWD.  
Based on my limited knowledge of the internals and rationale of find(1) anyway.

>Release-Note:

>Audit-Trail:
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/57313 CVS commit: src/usr.bin/find
Date: Sat, 1 Apr 2023 11:57:20 -0400

 Module Name:	src
 Committed By:	christos
 Date:		Sat Apr  1 15:57:20 UTC 2023

 Modified Files:
 	src/usr.bin/find: function.c main.c

 Log Message:
 PR/57313: Timo Buhrmester: Don't bail if "." cannot be opened. From FreeBSD


 To generate a diff of this commit:
 cvs rdiff -u -r1.79 -r1.80 src/usr.bin/find/function.c
 cvs rdiff -u -r1.31 -r1.32 src/usr.bin/find/main.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->needs-pullups
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Fri, 12 May 2023 18:54:47 +0000
State-Changed-Why:
should get at least into -10


State-Changed-From-To: needs-pullups->pending-pullups
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Wed, 02 Aug 2023 13:44:51 +0000
State-Changed-Why:
fixed in HEAD, pullups submitted for 10, 9, 9


From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/57313 CVS commit: [netbsd-10] src/usr.bin/find
Date: Fri, 4 Aug 2023 13:09:17 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Fri Aug  4 13:09:17 UTC 2023

 Modified Files:
 	src/usr.bin/find [netbsd-10]: function.c main.c

 Log Message:
 Pull up following revision(s) (requested by riastradh in ticket #305):

 	usr.bin/find/main.c: revision 1.32
 	usr.bin/find/function.c: revision 1.80

 PR/57313: Timo Buhrmester: Don't bail if "." cannot be opened. From FreeBSD


 To generate a diff of this commit:
 cvs rdiff -u -r1.79 -r1.79.6.1 src/usr.bin/find/function.c
 cvs rdiff -u -r1.31 -r1.31.40.1 src/usr.bin/find/main.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/57313 CVS commit: [netbsd-9] src/usr.bin/find
Date: Fri, 4 Aug 2023 13:10:35 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Fri Aug  4 13:10:35 UTC 2023

 Modified Files:
 	src/usr.bin/find [netbsd-9]: function.c main.c

 Log Message:
 Pull up following revision(s) (requested by riastradh in ticket #1701):

 	usr.bin/find/main.c: revision 1.32
 	usr.bin/find/function.c: revision 1.80

 PR/57313: Timo Buhrmester: Don't bail if "." cannot be opened. From FreeBSD


 To generate a diff of this commit:
 cvs rdiff -u -r1.77 -r1.77.2.1 src/usr.bin/find/function.c
 cvs rdiff -u -r1.31 -r1.31.32.1 src/usr.bin/find/main.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/57313 CVS commit: [netbsd-8] src/usr.bin/find
Date: Fri, 4 Aug 2023 13:12:00 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Fri Aug  4 13:12:00 UTC 2023

 Modified Files:
 	src/usr.bin/find [netbsd-8]: function.c main.c

 Log Message:
 Pull up following revision(s) (requested by riastradh in ticket #1879):

 	usr.bin/find/main.c: revision 1.32
 	usr.bin/find/function.c: revision 1.80

 PR/57313: Timo Buhrmester: Don't bail if "." cannot be opened. From FreeBSD


 To generate a diff of this commit:
 cvs rdiff -u -r1.75.8.2 -r1.75.8.3 src/usr.bin/find/function.c
 cvs rdiff -u -r1.31 -r1.31.22.1 src/usr.bin/find/main.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: pending-pullups->closed
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Sat, 05 Aug 2023 16:31:28 +0000
State-Changed-Why:
fixed in HEAD, pulled up to 10, 9, 8


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2023 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.