[PATCH] Finish the task 'Validate coredump format string'

Tiwei Bie btw at mail.ustc.edu.cn
Sun Mar 22 10:27:24 UTC 2015


On Sun, Mar 22, 2015 at 11:14:01AM +0100, Mateusz Guzik wrote:
> On Sun, Mar 22, 2015 at 05:19:40PM +0800, Tiwei Bie wrote:
> [..]
> 
> I was somehow convinced that tunables are dealt with other code.
> 
> If such sysctl handler is also called for tunables, the kernel should
> pass a flag or some other indicator so that the function knows it is
> dealing with a tunable and that would avoid locking and thus solve the
> problem.
> 

If a sysctl is registered as a tunable (CTLFLAG_TUN), when calling
sysctl_register_oid(), sysctl_load_tunable_by_oid_locked() will be
called to fetch the kenv setting (i.e. tunable setting defined in
loader.conf) to update the sysctl setting:

void
sysctl_register_oid(struct sysctl_oid *oidp)
{
        ......
        if ((oidp->oid_kind & CTLTYPE) != CTLTYPE_NODE &&
#ifdef VIMAGE
            (oidp->oid_kind & CTLFLAG_VNET) == 0 &&
#endif
            (oidp->oid_kind & CTLFLAG_TUN) != 0 &&
            (oidp->oid_kind & CTLFLAG_NOFETCH) == 0) {
                sysctl_load_tunable_by_oid_locked(oidp);
        }
}

sysctl_load_tunable_by_oid_locked() will fetch the kenv setting, and
call the sysctl handler, e.g. sysctl_kern_corefile() to update the
sysctl setting:

static void
sysctl_load_tunable_by_oid_locked(struct sysctl_oid *oidp)
{
        ......
        case CTLTYPE_STRING:
                penv = kern_getenv(path + rem);
                if (penv == NULL)
                        return;
                req.newlen = strlen(penv);
                req.newptr = penv;
                break;
        default:
                return;
        }
        error = sysctl_root_handler_locked(oidp, oidp->oid_arg1,
            oidp->oid_arg2, &req);
        if (error != 0)
                printf("Setting sysctl %s failed: %d\n", path, error);
        ......
}

The tunable setting is just a "name"=value format in kenv. And the kenv
codes have no idea of the meaning of the "name". It can also be modified
later when system is up by `kenv' command. And the corresponding sysctl
setting won't be affected any more.

> I'm wondering if we should go a little bit further and get rid of
> static char corefilename[MAXPATHLEN]
> 
> and have a static char *corefilename instead.
> 
> A dedicated sysinit func could fetch and validate the tunable, if any.
> If no tunable was provided it would alloc memory for the default.
> 
> -- 
> Mateusz Guzik <mjguzik gmail.com>

Best regards,
Tiwei Bie



More information about the freebsd-hackers mailing list