* Determine whether the subject represented by cred can "see" * status of a mount point. * Returns: 0 for permitted, ENOENT otherwise. * XXX: This function should be called cr_canseemount() and should be * placed in kern_prot.c. */
| 3184 | * placed in kern_prot.c. |
| 3185 | */ |
| 3186 | int |
| 3187 | prison_canseemount(struct ucred *cred, struct mount *mp) |
| 3188 | { |
| 3189 | struct prison *pr; |
| 3190 | struct statfs *sp; |
| 3191 | size_t len; |
| 3192 | |
| 3193 | pr = cred->cr_prison; |
| 3194 | if (pr->pr_enforce_statfs == 0) |
| 3195 | return (0); |
| 3196 | if (pr->pr_root->v_mount == mp) |
| 3197 | return (0); |
| 3198 | if (pr->pr_enforce_statfs == 2) |
| 3199 | return (ENOENT); |
| 3200 | /* |
| 3201 | * If jail's chroot directory is set to "/" we should be able to see |
| 3202 | * all mount-points from inside a jail. |
| 3203 | * This is ugly check, but this is the only situation when jail's |
| 3204 | * directory ends with '/'. |
| 3205 | */ |
| 3206 | if (strcmp(pr->pr_path, "/") == 0) |
| 3207 | return (0); |
| 3208 | len = strlen(pr->pr_path); |
| 3209 | sp = &mp->mnt_stat; |
| 3210 | if (strncmp(pr->pr_path, sp->f_mntonname, len) != 0) |
| 3211 | return (ENOENT); |
| 3212 | /* |
| 3213 | * Be sure that we don't have situation where jail's root directory |
| 3214 | * is "/some/path" and mount point is "/some/pathpath". |
| 3215 | */ |
| 3216 | if (sp->f_mntonname[len] != '\0' && sp->f_mntonname[len] != '/') |
| 3217 | return (ENOENT); |
| 3218 | return (0); |
| 3219 | } |
| 3220 | |
| 3221 | void |
| 3222 | prison_enforce_statfs(struct ucred *cred, struct mount *mp, struct statfs *sp) |
no test coverage detected