Skip to content

refactor(kernel): fix gid field typing and drop dead len check - #265

Merged
Galfurian merged 1 commit into
developfrom
fix/257-258-utsname-gid-cleanup
Aug 26, 2026
Merged

refactor(kernel): fix gid field typing and drop dead len check#265
Galfurian merged 1 commit into
developfrom
fix/257-258-utsname-gid-cleanup

Conversation

@Galfurian

Copy link
Copy Markdown
Member

Summary

Clean up two type/validation inconsistencies found during the recent utsname and process review.

  • Remove the unreachable len < 0 validation from __gethostname().
  • Use gid_t rather than pid_t for process group-ID credential fields and their temporary snapshots.

Fixes #257.
Fixes #258.

Problem / motivation

#257 — unreachable hostname length validation

__gethostname() receives its length as a size_t:

static inline int __gethostname(char *name, size_t len)

but previously contained:

if (len < 0) {
    return -EINVAL;
}

Since size_t is unsigned, this condition can never be true. The branch was dead code, and its accompanying comment incorrectly suggested that negative lengths could reach the function and be rejected.

The only current caller passes SYS_LEN, so removing the check does not change runtime behavior.

#258 — GID fields typed as process IDs

task_struct declared the real and effective group IDs as:

pid_t rgid;
pid_t gid;

even though these fields represent group IDs and the tree provides the appropriate gid_t type.

This was inconsistent with the neighboring user-ID fields:

uid_t ruid;
uid_t uid;

and propagated into credential snapshots used by the transactional execve() path.

pgid remains pid_t, since a process-group ID is correctly represented using the process-ID type.

At present, pid_t and gid_t are both signed int, so this is a type-correctness cleanup rather than a behavioral or ABI change.

Changes

kernel/src/sys/utsname.c

  • Remove the impossible len < 0 check.
  • Remove the corresponding misleading comment.

kernel/inc/process/process.h

Change:

pid_t rgid;
pid_t gid;

to:

gid_t rgid;
gid_t gid;

kernel/src/process/process.c

Use gid_t for both credential snapshots that mirror task->gid:

gid_t saved_gid;
gid_t prev_gid;

No credential semantics or execve() behavior are changed.

Validation

  • git diff --check
  • Relevant build completed
  • Relevant automated tests completed
  • GID-related regression coverage completed

Validation details:

Build:
- clean build completed successfully

Canonical regression:
- make qemu-test completed successfully
- QEMU guest exit: 33
- userspace suite: 52/52 passed

GID-related coverage:
- t_gid: passed
- t_groups: passed
- t_grp: passed

Static verification:
- git diff --check clean
- working tree clean

Scope

  • Changes are limited to the two reported cleanup issues.
  • No runtime behavior is intentionally changed.
  • pgid remains correctly typed as pid_t.
  • No unrelated utsname, credential, or execve() changes are included.

The two issues are combined because both are small, behavior-neutral type/source correctness cleanups discovered during the same review pass, and together remain a narrowly scoped kernel cleanup.

Related issues

Fixes #257.
Fixes #258.

Two cleanups from the utsname/process review:

- task_struct declares rgid/gid as pid_t although gid_t exists and the
  uid mirror fields below them use uid_t; fix the fields and the two
  credential snapshots in process.c that copied the wrong type
  (issue #258).
- __gethostname's  guard is dead code: len is size_t, so the
  comparison is always false and the -EINVAL branch unreachable; remove
  the check and its comment (issue #257).
@Galfurian
Galfurian merged commit 8ec4697 into develop Aug 26, 2026
4 checks passed
@Galfurian
Galfurian deleted the fix/257-258-utsname-gid-cleanup branch August 26, 2026 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant