Hi, a quick review:

On Tue, Nov 26, 2024 at 10:43 AM Damien Zammit via Bug reports for the
GNU Hurd <bug-hurd@gnu.org> wrote:
> +static void
> +smp(char * const argv[])

Style nitpick: space before the paren.

> +{
> +  int err;

error_t rather

> +  unsigned int pset_count;

mach_msg_type_number_t rather (it's likely the same type, but still)

> +  mach_port_t hostpriv;
> +  processor_set_name_array_t psets = {0};
> +  processor_set_t slave_pset = {0};

It's not an array in C sense, so if you want to zero-initialize it, =
MACH_PORT_NULL will do.

> +  if (get_privileged_ports (&hostpriv, NULL))
> +    error (1, 0, "Must be run as root for privileged cpu control");

err = get_privileged_ports (&hostpriv, NULL);
if (err)
  error (1, err, "......");

> +  err = host_processor_sets (hostpriv, &psets, &pset_count);
> +  if (err)
> +    error (1, 0, "Cannot get list of host processor sets");

error (1, err, "....")

> +  if (pset_count < 2)
> +    error (1, 0, "gnumach does not have the expected processor sets, are you 
> running smp kernel?");
> +
> +  err = host_processor_set_priv (hostpriv, psets[1], &slave_pset);
> +  if (err)
> +    error (1, 0, "Cannot get access to slave processor set");

same here

> +
> +  err = task_assign(mach_task_self(), slave_pset, FALSE);

...spaces before the parens...

> +  if (err)
> +    error (1, 0, "Cannot assign task self to slave processor set");

err here too

> +  /* Drop privileges from suid binary */
> +  setuid(getuid());

*Before* you do that, it's very important that you deallocate the
ports you acquired above: hostpriv, all of psets, and slave_pset.
Moreover, you also have to deallocate _hurd_host_priv.

> +  execve(argv[1], &argv[1], environ);

You should use execvp over execve here.

> +  /* NOT REACHED */

It is reached if there was an error, e.g. the binary doesn't exist. So:

error (1, errno, "failed to execute %s", argv[1]);

Sergey

Reply via email to