From patchwork Fri Oct 9 00:44:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 11824783 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0DD9B139F for ; Fri, 9 Oct 2020 00:45:11 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BE1652224B for ; Fri, 9 Oct 2020 00:45:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="OfQwv/Hb"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="JcIdK8+j" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BE1652224B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=lHQMB/QowiS/NzPi/FlI6yfO+aaUgUaAwJybPIJX604=; b=OfQwv/HbKiKeolTiUtZZxknrA uud9L7B0Yr0/i4DS42hLpM0x5cKYbeVrofAEeYp9aw8GdghtLTtxMSlcA+4lDGiEcmt5s8JEED2oz a9I7dq3RV+oR8SfhP5Tv1O4ujGZn3k0suY1Jp6Hbu5VTc/JIlf2Tp+ArrnfsCXDXlFcpRzLD4IjnS 5A9FNLUiySzvxGKpYECEYlXneWS+/U3yC91sXCKfwdE3ugKvcC4itIE+UivCn76Frppfefm8xJKbG Xdv7HxgijSN4Lqw/Ob2O3vgwyqDQti5VvQ3qkRMEhq8LjFq5aKcCCLhIKSK4qbHyfrgRgNJKTicmT DFx6y0yyg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQgWl-0001wK-CZ; Fri, 09 Oct 2020 00:44:55 +0000 Received: from mail-qt1-x84a.google.com ([2607:f8b0:4864:20::84a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQgWc-0001tZ-Vx for linux-arm-kernel@lists.infradead.org; Fri, 09 Oct 2020 00:44:48 +0000 Received: by mail-qt1-x84a.google.com with SMTP id o25so2101088qtt.3 for ; Thu, 08 Oct 2020 17:44:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=DiXgOtW41EBiKZO8ua1O6hkUcsVE3S9bgdto7K9hmgU=; b=JcIdK8+jrEJA2Ll+s+2DE2KxzvMCdK6Q+qxt+QqYpMBUAITtVMcbupIRpSbL6EdaKv 2jAMr3m3+1X8iWYiKkNFPbQDGkNXmTVBP7p7Ue43vpxGdo+D0RGqkoYBUDDEoLg0skgo rznN+zaOFguGVQ/HZEjlNw7jtkiK5TZ8k3v4McJHXgqP57ztnD0MXA5ZOIlZKdVzv+Qt 7bXYtPAWvO1isDw+buWzOysgHDuAlG59Tn1ukFiKQdoOLnJ7jDu1Iefsxp0UOZ807t7p +P9FMa1xu4pyrGzcAvNVhqf9GvJGqY9NsbInLCpk7T7uwcMHgEk1cZYpFLJDD95u6NaU 9Y9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=DiXgOtW41EBiKZO8ua1O6hkUcsVE3S9bgdto7K9hmgU=; b=Rs9m02ksmlwh3cz7mZUKhsn5iyXqRs1axPENToMef8kpGDrmnCd/EgLMyKVb6JcFKW x4DP2gztOcbhUe2EQyc+vuIF8j58u1FN+FQpSTLT9S2t/i5rQicSOEZoMmgTptXL/xEQ j/S2ApQBxiONA+Kq6m77NVPAb+7yoCFdB+JgLIULF/ZejI1MDyIybYdG8b3v2veRJp4W 8wj3gHQaVST1j/OKxJdf3QFJlsw2UsiNUd+ZY2VNZuXVwHEIN/wRR4FWiV9c+uaPBk9h Bn8xs12hxQutaaVrLWIz12C/CLFhB3Z8W58zyLzJZmKqUkhhMLPQu7W18QA3PSguTX8d uuKA== X-Gm-Message-State: AOAM531zmcoWcngLcVk7AXXN5C41kcCF7iJqmUup6cJc/edfX+uWcyZI uFpQrK72AdNIMhXVA00+k/gVabw= X-Google-Smtp-Source: ABdhPJxj5fUuoORZeJ30tIhqrBKrBMQ5KIPT0cYLAAFWFeKDRReDGdWJfQsyCH0rdfUMKYA2nbkz/+0= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2ce:0:7220:84ff:fe09:385a]) (user=pcc job=sendgmr) by 2002:a0c:ffb2:: with SMTP id d18mr10475143qvv.44.1602204283427; Thu, 08 Oct 2020 17:44:43 -0700 (PDT) Date: Thu, 8 Oct 2020 17:44:16 -0700 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.1011.ga647a8990f-goog Subject: [PATCH v11 5/8] signal: define the SA_UNSUPPORTED bit in sa_flags From: Peter Collingbourne To: Catalin Marinas , Evgenii Stepanov , Kostya Serebryany , Vincenzo Frascino , Dave Martin , Will Deacon , Oleg Nesterov , "Eric W. Biederman" , "James E.J. Bottomley" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201008_204447_035496_443B13F5 X-CRM114-Status: GOOD ( 17.82 ) X-Spam-Score: -7.7 (-------) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-7.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:84a listed in] [list.dnswl.org] -7.5 USER_IN_DEF_DKIM_WL From: address is in the default DKIM white-list -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.0 DKIMWL_WL_MED DKIMwl.org - Medium trust sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrey Konovalov , Helge Deller , Kevin Brodsky , linux-api@vger.kernel.org, David Spickett , Peter Collingbourne , Linux ARM , Richard Henderson Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Define a sa_flags bit, SA_UNSUPPORTED, which will never be supported in the uapi. The purpose of this flag bit is to allow userspace to distinguish an old kernel that does not clear unknown sa_flags bits from a kernel that supports every flag bit. In other words, if userspace does something like: act.sa_flags |= SA_UNSUPPORTED; sigaction(SIGSEGV, &act, 0); sigaction(SIGSEGV, 0, &oldact); and finds that SA_UNSUPPORTED remains set in oldact.sa_flags, it means that the kernel cannot be trusted to have cleared unknown flag bits from sa_flags, so no assumptions about flag bit support can be made. Signed-off-by: Peter Collingbourne Reviewed-by: Dave Martin Link: https://linux-review.googlesource.com/id/Ic2501ad150a3a79c1cf27fb8c99be342e9dffbcb --- v11: - clarify the commit message include/uapi/asm-generic/signal-defs.h | 7 +++++++ kernel/signal.c | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/include/uapi/asm-generic/signal-defs.h b/include/uapi/asm-generic/signal-defs.h index 493953fe319b..0126ebda4d31 100644 --- a/include/uapi/asm-generic/signal-defs.h +++ b/include/uapi/asm-generic/signal-defs.h @@ -14,6 +14,12 @@ * SA_RESTART flag to get restarting signals (which were the default long ago) * SA_NODEFER prevents the current signal from being masked in the handler. * SA_RESETHAND clears the handler when the signal is delivered. + * SA_UNSUPPORTED is a flag bit that will never be supported. Kernels from + * before the introduction of SA_UNSUPPORTED did not clear unknown bits from + * sa_flags when read using the oldact argument to sigaction and rt_sigaction, + * so this bit allows flag bit support to be detected from userspace while + * allowing an old kernel to be distinguished from a kernel that supports every + * flag bit. * * SA_ONESHOT and SA_NOMASK are the historical Linux names for the Single * Unix names RESETHAND and NODEFER respectively. @@ -42,6 +48,7 @@ #ifndef SA_RESETHAND #define SA_RESETHAND 0x80000000 #endif +#define SA_UNSUPPORTED 0x00000400 #define SA_NOMASK SA_NODEFER #define SA_ONESHOT SA_RESETHAND diff --git a/kernel/signal.c b/kernel/signal.c index 2ef8c238679e..018c19f6cf66 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -3984,6 +3984,12 @@ int do_sigaction(int sig, struct k_sigaction *act, struct k_sigaction *oact) if (oact) *oact = *k; + /* + * Make sure that we never accidentally claim to support SA_UNSUPPORTED, + * e.g. by having an architecture use the bit in their uapi. + */ + BUILD_BUG_ON(UAPI_SA_FLAGS & SA_UNSUPPORTED); + /* * Clear unknown flag bits in order to allow userspace to detect missing * support for flag bits and to allow the kernel to use non-uapi bits