Skip to content

Fix code quality issues#587

Merged
jnovy merged 1 commit intocontainers:mainfrom
jnovy:582
Sep 5, 2025
Merged

Fix code quality issues#587
jnovy merged 1 commit intocontainers:mainfrom
jnovy:582

Conversation

@jnovy
Copy link
Collaborator

@jnovy jnovy commented Sep 4, 2025

  • Fix strncpy missing null termination in conn_sock.c
  • Replace malloc with g_malloc for consistency in ctr_exit.c
  • Add bounds validation for sscanf parsing in ctrl.c
  • Fix signal safety: change volatile pid_t to sig_atomic_t
  • Add null check for cgroup2_path before use
  • Clean up outdated TODO/FIXME comments

These changes address potential buffer safety, memory allocation consistency, signal safety, and logic issues flagged during code review.

Fixes: #582

@jnovy jnovy requested a review from mtrmac September 4, 2025 07:31
Copy link
Collaborator

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes here LGTM.

Note that this by no means handles everything from #582 , e.g. see the example below. But, also, I’m not going to be able to follow up on everything there, so the resolution, if any, is entirely up to you.

src/conmon.c Outdated
pexit("seccomp notify socket specified without any plugin");
seccomp_listener = setup_seccomp_socket(opt_seccomp_notify_socket);
#else
pexit("seccomp support not present");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E.g. this is still printing an errno-derived value.

@jnovy jnovy force-pushed the 582 branch 3 times, most recently from 8ec43cd to 769b735 Compare September 4, 2025 08:42
@packit-as-a-service
Copy link

Ephemeral COPR build failed. @containers/packit-build please check.

@jnovy jnovy force-pushed the 582 branch 2 times, most recently from 882bca5 to e7c5880 Compare September 4, 2025 08:53
@jnovy
Copy link
Collaborator Author

jnovy commented Sep 4, 2025

Thanks, I just replaced the pexit() with nexit() so no bogus errno is printed.

src/cli.c Outdated
"Path to the socket where the seccomp notification fd is received", NULL},
{"seccomp-notify-plugins", 0, 0, G_OPTION_ARG_STRING, &opt_seccomp_notify_plugins,
"Plugins to use for managing the seccomp notifications", NULL},
{"seccomp-notify-allowed", 0, 0, G_OPTION_ARG_NONE, &opt_seccomp_notify_allowed, "Allow seccomp notify annotations", NULL},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the man page need updating for the new option?

(If this didn’t work for … years, my first instinct would be to delete the code wholesale, but I know nothing of the history.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know much about the history either. @giuseppe ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, I'd prefer to keep it for now unless @giuseppe has different opinion - I added the --seccomp-notify-allowed option to the man page.

Copy link
Member

@giuseppe giuseppe Sep 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was added to experiment with crun-style seccomp notification plugins: https://github.com/containers/crun/blob/main/contrib/seccomp-notify-plugin-example/full.c

Not sure if anyone is using it, we didn't follow up to expose it in Podman because using them is quite difficult (i.e. requires a binary handler)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but why do we need opt_seccomp_notify_allowed?

If they are specified in opt_seccomp_notify_plugins we use them, otherwise not. Why another bool?

If anything, it should be a separate commit

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I removed the seccomp-notify-allowed as opt_seccomp_notify_plugins already handles that.

- Fix strncpy missing null termination in conn_sock.c
- Replace malloc with g_malloc for consistency in ctr_exit.c
- Add bounds validation for sscanf parsing in ctrl.c
- Fix signal safety: change volatile pid_t to sig_atomic_t
- Add null check for cgroup2_path before use
- Clean up outdated TODO/FIXME comments

These changes address potential buffer safety, memory allocation
consistency, signal safety, and logic issues flagged during code review.

Fixes: containers#582

Signed-off-by: Jindrich Novy <jnovy@redhat.com>
@jnovy
Copy link
Collaborator Author

jnovy commented Sep 5, 2025

I removed all seccomp related bits from this PR and filed issue #591 to address seccomp related fixes separately.

@jnovy jnovy merged commit e579e76 into containers:main Sep 5, 2025
29 of 34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assorted suspicions

3 participants