I've been doing some shell writing and came across a recommendation for access()
to check whether a file exists, can be read, etc. Seems super easy to implement and faster than stat()
. When I started looking at the man page for it, I noticed that it is NOT recommended for use because it can lead to a security hole. The man page says this:
Using access() to check if a user is authorized to e.g. open a file
before actually doing so using open(2) creates a security hole,
because the user might exploit the short time interval between
checking and opening the file to manipulate it.
Does anyone know how this can be exploited or if it pertains only to using open()
after checking a file? I know that a lot of people say to use stat()
instead, but access()
is so easy to implement, especially for the shell that I used it for.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…