From nobody Mon Feb 9 14:17:09 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1666769619; cv=none; d=zohomail.com; s=zohoarc; b=TRWE4J3mPQzLG6hWcvAGNQWgi+2i1nAxy/udy7iyWIusDG6zCtjwRcG9/JSE+YSz+fIiDjP70KMq0MZdPcbVtF2zGxf7sEIFlUHFiYW4T4XCKiv+Q0VDyx28wfGEEOK82hKghci2fmFkFcwE5/FWwVoMR1Gh5kwD7luPsItdCP4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666769619; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=/kr2jtd/zPDWs9WSyBzud1VT+xvvLZMz04sPwPHqtHY=; b=DU3MkbgxW740a6rNRQwN79uNlA8xJy3gUJfV+ns3zuofhmjwLVbN9IgJ2m24tDtPEoL8bi2uhkuDCooueFY8N8IRpV07NFeyir3aoQy7SOUWY/ZXvANW1hBtccuBXmAUtF0VTSVVbCsTh1sEeLV1I/0FJqpyfYxURkY7ahBvaIg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1666769619391521.0641801027573; Wed, 26 Oct 2022 00:33:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onasO-0002A3-1l; Wed, 26 Oct 2022 03:31:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onasH-00021k-VK for qemu-devel@nongnu.org; Wed, 26 Oct 2022 03:30:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onasF-0002iX-F8 for qemu-devel@nongnu.org; Wed, 26 Oct 2022 03:30:53 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-93-nyUUrFoJNgO2tOa9lYI7RQ-1; Wed, 26 Oct 2022 03:30:40 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 481633C0DDD7 for ; Wed, 26 Oct 2022 07:30:30 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id F07E4145888C; Wed, 26 Oct 2022 07:30:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666769450; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/kr2jtd/zPDWs9WSyBzud1VT+xvvLZMz04sPwPHqtHY=; b=Py9HMcOUjG6Euh9kYpMrObltoo1PIKUZOttYhDUx6E5YVMRbP/Ahwh6wSvCDAidsrYLEQH jQnqYjL+4uhLqXyvfKVQr6Cvy+DAZvrFfBWsO1MqoV+yFGFAJJO9CkiBFYj5ODvjZtjol5 +gEoZrw4pSsdQ+t2dKdaZ+FZya8/oDE= X-MC-Unique: nyUUrFoJNgO2tOa9lYI7RQ-1 From: Michal Privoznik To: qemu-devel@nongnu.org Cc: berrange@redhat.com Subject: [PATCH v2] seccomp: Get actual errno value from failed seccomp functions Date: Wed, 26 Oct 2022 09:30:24 +0200 Message-Id: <80c86614e3b21dda074b81fe9c3866fdbbb7420e.1666769319.git.mprivozn@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=mprivozn@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.517, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666769620062100001 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 Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Daniel P. Berrang=C3=A9 --- v2 of: https://lists.gnu.org/archive/html/qemu-devel/2022-10/msg04509.html diff to v1: - added comment when setting SYSRAWRC attribute per Philippe's suggestion meson.build | 9 +++++++++ softmmu/qemu-seccomp.c | 13 +++++++++++++ 2 files changed, 22 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 =20 seccomp =3D not_found +seccomp_has_sysrawrc =3D false if not get_option('seccomp').auto() or have_system or have_tools seccomp =3D dependency('libseccomp', version: '>=3D2.3.0', required: get_option('seccomp'), method: 'pkg-config', kwargs: static_kwargs) + if seccomp.found() + seccomp_has_sysrawrc =3D cc.has_header_symbol('seccomp.h', + 'SCMP_FLTATR_API_SYSRAWRC', + dependencies: seccomp) + endif endif =20 libcap_ng =3D 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..d66a2a1226 100644 --- a/softmmu/qemu-seccomp.c +++ b/softmmu/qemu-seccomp.c @@ -312,6 +312,19 @@ static int seccomp_start(uint32_t seccomp_opts, Error = **errp) goto seccomp_return; } =20 +#if defined(CONFIG_SECCOMP_SYSRAWRC) + /* + * This must be the first seccomp_attr_set() call to have full + * error propagation from subsequent seccomp APIs. + */ + rc =3D seccomp_attr_set(ctx, SCMP_FLTATR_API_SYSRAWRC, 1); + if (rc !=3D 0) { + error_setg_errno(errp, -rc, + "failed to set seccomp rawrc attribute"); + goto seccomp_return; + } +#endif + rc =3D seccomp_attr_set(ctx, SCMP_FLTATR_CTL_TSYNC, 1); if (rc !=3D 0) { error_setg_errno(errp, -rc, --=20 2.37.4