| 3219 | } |
| 3220 | |
| 3221 | void |
| 3222 | prison_enforce_statfs(struct ucred *cred, struct mount *mp, struct statfs *sp) |
| 3223 | { |
| 3224 | char jpath[MAXPATHLEN]; |
| 3225 | struct prison *pr; |
| 3226 | size_t len; |
| 3227 | |
| 3228 | pr = cred->cr_prison; |
| 3229 | if (pr->pr_enforce_statfs == 0) |
| 3230 | return; |
| 3231 | if (prison_canseemount(cred, mp) != 0) { |
| 3232 | bzero(sp->f_mntonname, sizeof(sp->f_mntonname)); |
| 3233 | strlcpy(sp->f_mntonname, "[restricted]", |
| 3234 | sizeof(sp->f_mntonname)); |
| 3235 | return; |
| 3236 | } |
| 3237 | if (pr->pr_root->v_mount == mp) { |
| 3238 | /* |
| 3239 | * Clear current buffer data, so we are sure nothing from |
| 3240 | * the valid path left there. |
| 3241 | */ |
| 3242 | bzero(sp->f_mntonname, sizeof(sp->f_mntonname)); |
| 3243 | *sp->f_mntonname = '/'; |
| 3244 | return; |
| 3245 | } |
| 3246 | /* |
| 3247 | * If jail's chroot directory is set to "/" we should be able to see |
| 3248 | * all mount-points from inside a jail. |
| 3249 | */ |
| 3250 | if (strcmp(pr->pr_path, "/") == 0) |
| 3251 | return; |
| 3252 | len = strlen(pr->pr_path); |
| 3253 | strlcpy(jpath, sp->f_mntonname + len, sizeof(jpath)); |
| 3254 | /* |
| 3255 | * Clear current buffer data, so we are sure nothing from |
| 3256 | * the valid path left there. |
| 3257 | */ |
| 3258 | bzero(sp->f_mntonname, sizeof(sp->f_mntonname)); |
| 3259 | if (*jpath == '\0') { |
| 3260 | /* Should never happen. */ |
| 3261 | *sp->f_mntonname = '/'; |
| 3262 | } else { |
| 3263 | strlcpy(sp->f_mntonname, jpath, sizeof(sp->f_mntonname)); |
| 3264 | } |
| 3265 | } |
| 3266 | |
| 3267 | /* |
| 3268 | * Check with permission for a specific privilege is granted within jail. We |
no test coverage detected