With FAN_DENY response, user trying to perform the filesystem operation gets an error with errno set to EPERM. It is useful for hierarchical storage management (HSM) service to be able to deny access for reasons more diverse than EPERM, for example EAGAIN, if HSM could retry the operation later. Allow fanotify groups with priority FAN_CLASSS_PRE_CONTENT to responsd to permission events with the response value FAN_DENY_ERRNO(errno), instead of FAN_DENY to return a custom error. Limit custom error values to errors expected on read(2)/write(2) and open(2) of regular files. This list could be extended in the future. Userspace can test for legitimate values of FAN_DENY_ERRNO(errno) by writing a response to an fanotify group fd with a value of FAN_NOFD in the fd field of the response. The change in fanotify_response is backward compatible, because errno is written in the high 8 bits of the 32bit response field and old kernels reject respose value with high bits set.
Showing the changes to include/uapi (1 of 5 files). Show all
Unified · Split
| @@ -235,6 +235,13 @@ struct fanotify_response_info_audit_rule { · 234 unmodified lines | |||
| 235 | /* Legit userspace responses to a _PERM event */ | 235 | /* Legit userspace responses to a _PERM event */ |
| 236 | #define FAN_ALLOW 0x01 | 236 | #define FAN_ALLOW 0x01 |
| 237 | #define FAN_DENY 0x02 | 237 | #define FAN_DENY 0x02 |
| 238 | /* errno other than EPERM can specified in upper byte of deny response */ | ||
| 239 | #define FAN_ERRNO_BITS 8 | ||
| 240 | #define FAN_ERRNO_SHIFT (32 - FAN_ERRNO_BITS) | ||
| 241 | #define FAN_ERRNO_MASK ((1 << FAN_ERRNO_BITS) - 1) | ||
| 242 | #define FAN_DENY_ERRNO(err) \ | ||
| 243 | (FAN_DENY | ((((__u32)(err)) & FAN_ERRNO_MASK) << FAN_ERRNO_SHIFT)) | ||
| 244 | |||
| 238 | #define FAN_AUDIT 0x10 /* Bitmask to create audit record for result */ | 245 | #define FAN_AUDIT 0x10 /* Bitmask to create audit record for result */ |
| 239 | #define FAN_INFO 0x20 /* Bitmask to indicate additional information */ | 246 | #define FAN_INFO 0x20 /* Bitmask to indicate additional information */ |
| 240 | 247 | ||