From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: "Michal Privoznik" <mprivozn@redhat.com>,
qemu-devel@nongnu.org, "Daniel P. Berrangé" <berrange@redhat.com>
Subject: Re: [PATCH] seccomp: Get actual errno value from failed seccomp functions
Date: Tue, 25 Oct 2022 15:13:24 +0200 [thread overview]
Message-ID: <6d4f3fc9-b91e-3978-affd-fbe8e29671c2@linaro.org> (raw)
In-Reply-To: <b971585976862e52df4c373286104dd0540be8b7.1666699164.git.mprivozn@redhat.com>
Cc'ing Daniel (maintainer)
On 25/10/22 13:59, Michal Privoznik wrote:
> Upon failure, a libseccomp API returns actual errno value very
> rarely. Fortunately, after its commit 34bf78ab (contained in
> 2.5.0 release), the SCMP_FLTATR_API_SYSRAWRC attribute can be set
> which makes subsequent APIs return true errno on failure.
>
> This is especially critical when seccomp_load() fails, because
> generic -ECANCELED says nothing.
>
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
> meson.build | 9 +++++++++
> softmmu/qemu-seccomp.c | 9 +++++++++
> 2 files changed, 18 insertions(+)
>
> diff --git a/meson.build b/meson.build
> index b686dfef75..5f114c89d9 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -636,10 +636,16 @@ if vmnet.found() and not cc.has_header_symbol('vmnet/vmnet.h',
> endif
>
> seccomp = not_found
> +seccomp_has_sysrawrc = false
> if not get_option('seccomp').auto() or have_system or have_tools
> seccomp = dependency('libseccomp', version: '>=2.3.0',
> required: get_option('seccomp'),
> method: 'pkg-config', kwargs: static_kwargs)
> + if seccomp.found()
> + seccomp_has_sysrawrc = cc.has_header_symbol('seccomp.h',
> + 'SCMP_FLTATR_API_SYSRAWRC',
> + dependencies: seccomp)
> + endif
> endif
>
> libcap_ng = not_found
> @@ -1849,6 +1855,9 @@ config_host_data.set('CONFIG_RDMA', rdma.found())
> config_host_data.set('CONFIG_SDL', sdl.found())
> config_host_data.set('CONFIG_SDL_IMAGE', sdl_image.found())
> config_host_data.set('CONFIG_SECCOMP', seccomp.found())
> +if seccomp.found()
> + config_host_data.set('CONFIG_SECCOMP_SYSRAWRC', seccomp_has_sysrawrc)
> +endif
> config_host_data.set('CONFIG_SNAPPY', snappy.found())
> config_host_data.set('CONFIG_TPM', have_tpm)
> config_host_data.set('CONFIG_USB_LIBUSB', libusb.found())
> diff --git a/softmmu/qemu-seccomp.c b/softmmu/qemu-seccomp.c
> index deaf8a4ef5..05abf257c4 100644
> --- a/softmmu/qemu-seccomp.c
> +++ b/softmmu/qemu-seccomp.c
> @@ -312,6 +312,15 @@ static int seccomp_start(uint32_t seccomp_opts, Error **errp)
> goto seccomp_return;
> }
>
> +#if defined(CONFIG_SECCOMP_SYSRAWRC)
Maybe add some comment here such:
/*
* This must be the first seccomp_attr_set() call to have full
* error propagation.
*/
> + rc = seccomp_attr_set(ctx, SCMP_FLTATR_API_SYSRAWRC, 1);
> + if (rc != 0) {
> + error_setg_errno(errp, -rc,
> + "failed to set seccomp rawrc attribute");
> + goto seccomp_return;
> + }
> +#endif
> +
> rc = seccomp_attr_set(ctx, SCMP_FLTATR_CTL_TSYNC, 1);
> if (rc != 0) {
> error_setg_errno(errp, -rc,
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
prev parent reply other threads:[~2022-10-25 13:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-25 11:59 [PATCH] seccomp: Get actual errno value from failed seccomp functions Michal Privoznik
2022-10-25 13:13 ` Philippe Mathieu-Daudé [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6d4f3fc9-b91e-3978-affd-fbe8e29671c2@linaro.org \
--to=philmd@linaro.org \
--cc=berrange@redhat.com \
--cc=mprivozn@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).