access() Security Hole

后端 未结 3 1793
暖寄归人
暖寄归人 2020-12-21 06:41

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

3条回答
  •  青春惊慌失措
    2020-12-21 07:29

    That is a TOCTOU race (Time of Check to Time of Update). A malicious user could substitute a file he has access to for a symlink to something he doesn't have access to between the access() and the open() calls. Use faccessat() or fstat(). In general, open a file once, and use f*() functions on it (e.g: fchown(), ...).

提交回复
热议问题