From patchwork Thu Apr 22 06:44:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 12217733 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3457DC433B4 for ; Thu, 22 Apr 2021 06:47:13 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 8629B61448 for ; Thu, 22 Apr 2021 06:47:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8629B61448 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+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Cc:To:From:Subject:Mime-Version:Message-Id:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=goncFye7F7RBo1tJKZ/aKB8xTQCgjrJ/5VIPqw+5OC4=; b=DqDL51Xi4ooPa0tSxrIiSQWi1e J3dQdwexYEtXLXTqfaDOMUOheZS7HwwNlNEn4NZ2lclwgU2rQEMcffc5aNpSWMIlWUGJqZC3nKWsW ZODztTGVZE+9Vqs6tbhOleuPkOFIgAtuSN1Jv7nD38xfNN1R80QtmIFVhdw2coHl1hZ9C4wJu+NYC SWVZYjG9VEUj3NT9rUIR8QYSZa2w7OEihYctMb6rJDzo6O7xQiJUcvOaBYSDg/0iBHlZB2Ma0A+Zy KdqYq8QSddD4FRpVzfsUVeAP/7avHyu8H2cCDVmZv27yvV3PMa0vSmpVZ8JSmiSLmqJq2Ngut8tyt LOwZ8MSw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lZT5E-00G32R-L4; Thu, 22 Apr 2021 06:45:05 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lZT5B-00G31u-Oo for linux-arm-kernel@desiato.infradead.org; Thu, 22 Apr 2021 06:45:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Type:Cc:To:From:Subject: Mime-Version:Message-Id:Date:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To:References; bh=l+qKKt5CthNo7gsKeiDmyb/kZ1TcAtPvmD2Gk6Cbjnk=; b=0sdTGi4WjWE7eSAkpfZRwPMm8L HBto4yT4x3cGh2iZKyjtyb6M+/JpxArVIfKt20nbsQEd1RipCn+cKdXpKoOLCjbjxbcUFKgvs8fWj ShAByPqWKoggMEh5rljDAuyGl+QvRSbUsh9MenprnqBNuhQ90sMaZxKhc+XaqWQHk5FtWI4MNGh+e IvQTVddFmSOrDlUKHK0CHNKSF6eKh0eM6361cMhQfmmqzZNn4PKWDVJacxKpYxZVYGejj75/TjuV8 x/msifeBnBPcu4EMjleK3eTVSxneOTUxS3PBvQrCb/EU1MJitzzq2GGetNb7JqrmscC4A/B9dqvpK OttRsXbg==; Received: from mail-qt1-x849.google.com ([2607:f8b0:4864:20::849]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lZT59-00DQ6y-1H for linux-arm-kernel@lists.infradead.org; Thu, 22 Apr 2021 06:45:00 +0000 Received: by mail-qt1-x849.google.com with SMTP id d10-20020a05622a100ab02901b8224bae03so9356975qte.2 for ; Wed, 21 Apr 2021 23:44:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=l+qKKt5CthNo7gsKeiDmyb/kZ1TcAtPvmD2Gk6Cbjnk=; b=b1iMBV9GjdZUYj2yI91PEybzTlsso3VQDe8xFMroa8ouR/ttvj3knfM95AcNp1o84N g3TViOskADOkMIRz01ZVq4DUjQZyZYMngikbAuJ1Osp/zLsc28t3HSQ2FpA3Ga3BsWKu rb2XTXvhd8z9TEDkexQdPsGGr/zaZNAV6mlSti35luArLtEty+Y9rHswJOSwg9ygNTBn 9XompmxpjhsB013aKMMkXTACZtH8PEBV7p+ZV1Z6tknsyI8DvVaQ5ujGbpl8USHDp0AC rCRYL7yckdt0n+qQPGJ5E8F2K6ndnfTtbd1GP0VFWMkO0OHeIaswtKYYuDFLF5XwBoce 3B2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=l+qKKt5CthNo7gsKeiDmyb/kZ1TcAtPvmD2Gk6Cbjnk=; b=NE0gCB7tHsgfffT69K0twMDrX/3c0/YCNdXO/kSdTEGKW4l7YVwQWxBdGZIYIWsCbf 0ZUE6HXHIOxRLCY4zhA+0/s8Ef84Fi8HPl6DDAcd5g4IvT1MsZoh7xEx9LV1ijshTeUu tjxBeiZvxjWfNK6SFxZ7lfGzPlpo2tSjveNeVWy3w90UjXUNePROYCD5tZtv1Zv2HLeP qcajOoB74bn+x0QMZIAXr/Ks1GIUJzBaTlJuUl/sfOIXBQGJ5dUH7J1EbQ/RRSNlm/Zv xhSbZkgLx7+dVuJ0Lz3m7Ek4SZKF6bM8+khkR+j4prujiRA7Kd0qZRysoDmWK78A2gls 1hEA== X-Gm-Message-State: AOAM530dZXFEGkM2yzRhtyD095sgufw8DIzfdtDzgd/bnc5Pwl6cxIzV jNQQ27VF3CzfiApDOwd2pYbDgX8fGA== X-Google-Smtp-Source: ABdhPJxKnTjrg7o9jl1LZdW4wy1+iae01OymOtOg+SLBRFzgbEQoqfWU08/k6ULzAeLc86G4rUyFprUPpg== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:6273:c89a:6562:e1ba]) (user=elver job=sendgmr) by 2002:a0c:f454:: with SMTP id h20mr1734578qvm.40.1619073896837; Wed, 21 Apr 2021 23:44:56 -0700 (PDT) Date: Thu, 22 Apr 2021 08:44:36 +0200 Message-Id: <20210422064437.3577327-1-elver@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.31.1.498.g6c1eba8ee3d-goog Subject: [PATCH tip 1/2] signal, perf: Fix siginfo_t by avoiding u64 on 32-bit architectures From: Marco Elver To: elver@google.com, peterz@infradead.org, mingo@redhat.com, tglx@linutronix.de Cc: m.szyprowski@samsung.com, jonathanh@nvidia.com, dvyukov@google.com, glider@google.com, arnd@arndb.de, christian@brauner.io, axboe@kernel.dk, pcc@google.com, oleg@redhat.com, kasan-dev@googlegroups.com, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210421_234459_100949_45F91044 X-CRM114-Status: GOOD ( 18.09 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On some architectures, like Arm, the alignment of a structure is that of its largest member. This means that there is no portable way to add 64-bit integers to siginfo_t on 32-bit architectures, because siginfo_t does not contain any 64-bit integers on 32-bit architectures. In the case of the si_perf field, word size is sufficient since there is no exact requirement on size, given the data it contains is user-defined via perf_event_attr::sig_data. On 32-bit architectures, any excess bits of perf_event_attr::sig_data will therefore be truncated when copying into si_perf. Since this field is intended to disambiguate events (e.g. encoding relevant information if there are more events of the same type), 32 bits should provide enough entropy to do so on 32-bit architectures. For 64-bit architectures, no change is intended. Fixes: fb6cc127e0b6 ("signal: Introduce TRAP_PERF si_code and si_perf to siginfo") Reported-by: Marek Szyprowski Tested-by: Marek Szyprowski Reported-by: Jon Hunter Signed-off-by: Marco Elver Tested-by: Jon Hunter --- Note: I added static_assert()s to verify the siginfo_t layout to arch/arm and arch/arm64, which caught the problem. I'll send them separately to arm&arm64 maintainers respectively. --- include/linux/compat.h | 2 +- include/uapi/asm-generic/siginfo.h | 2 +- tools/testing/selftests/perf_events/sigtrap_threads.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/compat.h b/include/linux/compat.h index c8821d966812..f0d2dd35d408 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h @@ -237,7 +237,7 @@ typedef struct compat_siginfo { u32 _pkey; } _addr_pkey; /* used when si_code=TRAP_PERF */ - compat_u64 _perf; + compat_ulong_t _perf; }; } _sigfault; diff --git a/include/uapi/asm-generic/siginfo.h b/include/uapi/asm-generic/siginfo.h index d0bb9125c853..03d6f6d2c1fe 100644 --- a/include/uapi/asm-generic/siginfo.h +++ b/include/uapi/asm-generic/siginfo.h @@ -92,7 +92,7 @@ union __sifields { __u32 _pkey; } _addr_pkey; /* used when si_code=TRAP_PERF */ - __u64 _perf; + unsigned long _perf; }; } _sigfault; diff --git a/tools/testing/selftests/perf_events/sigtrap_threads.c b/tools/testing/selftests/perf_events/sigtrap_threads.c index 9c0fd442da60..78ddf5e11625 100644 --- a/tools/testing/selftests/perf_events/sigtrap_threads.c +++ b/tools/testing/selftests/perf_events/sigtrap_threads.c @@ -44,7 +44,7 @@ static struct { } ctx; /* Unique value to check si_perf is correctly set from perf_event_attr::sig_data. */ -#define TEST_SIG_DATA(addr) (~(uint64_t)(addr)) +#define TEST_SIG_DATA(addr) (~(unsigned long)(addr)) static struct perf_event_attr make_event_attr(bool enabled, volatile void *addr) { From patchwork Thu Apr 22 06:44:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 12217731 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55567C433ED for ; Thu, 22 Apr 2021 06:47:07 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 9E4D561448 for ; Thu, 22 Apr 2021 06:47:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9E4D561448 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+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Cc: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=INqWa/17fvzzgWBFNf4w+46dgEmXZXpekyxFkvXLi8Y=; b=kXrnUpMH5E6IcS FdtRy003nOZHY9WVkO3KTv3FuFFDEz6CUEO4nOTToOD2U9//stvSbP/ATLalJUbjeG4gvfhSJKMF2 kefmD4kQKeE0TrNv2AqRzGXPX5ig4TVc/Meb9KxRKvi7V21MLCarVDyTBka3Lu3RWWaNmoHXr0bgg bxaDJ8v6e1uDHR+jPAQsXmZzVW0/TrtD2SjWMKE2jrfZXX8DCLOyjyj0exH1KVJFG4dhnyNFMxsa+ 36WSmAk+6Toj6LAjRNpzKsBY000Jcauk+gqIBQbTIAnxAoOraZ5dNgj3P7mU1WTBriZq3EoQrir82 9yuk9uF3WYrsDznl56PQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lZT5N-00G33Y-Rw; Thu, 22 Apr 2021 06:45:14 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lZT5H-00G336-1M for linux-arm-kernel@desiato.infradead.org; Thu, 22 Apr 2021 06:45:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Sugwskr8rXy42pZ1xDG6/Yn9grQzLU2kaW/tniDjvCM=; b=oGxi3e82gMiNxR64eht3Uvmzxd 4vErvUpa7kkTL1wM+JRsm0ogpXU9kKwCbWvhgHCtIn8TnuTH8cRCvjej4edF1qPLeVU5yExnryRfu bby+gfHB/SJLkugRe8ak1Cwmi5hLGLNBZuvoxRMfp6KipW9ekknwTazb4VhXLzEV6A0K9K/GHT3kc dTqL4Fr8q7XC3HnD/tP89zeelWQ9SoZKBQ2KiVOhClaOGjPoA8DjblgE9bxt03HH6TzMx9cIjq1pM EtOvG1mVx8KH+OokNTJpCT+RDUkSpomERvSbsU78VAmZ6NNQ/qlwPOf98RI8wb7ieC9c5VeJ+FoA7 yTmPTKuA==; Received: from mail-wr1-x44a.google.com ([2a00:1450:4864:20::44a]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lZT5E-00DQ7D-Ky for linux-arm-kernel@lists.infradead.org; Thu, 22 Apr 2021 06:45:05 +0000 Received: by mail-wr1-x44a.google.com with SMTP id y13-20020adfdf0d0000b02901029a3bf796so13378917wrl.15 for ; Wed, 21 Apr 2021 23:45:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Sugwskr8rXy42pZ1xDG6/Yn9grQzLU2kaW/tniDjvCM=; b=rlmZAOT4B8TFqAZfZ08hCQP6c8Lo5iDRtrCmUNvvQfPE2MM8TQVihWTTmzMuSendWu yX+RaWI3/1avKzx9airDR9aL48aJWg8GIWMZcHboD9GKsYqKNJkl1Sd8UbVlDroUbRxT B6+HRfVChEHZtk9KTA1SSqpw+ZHUQvGm1Uz1fY6Rz2kq/qq6GvJzN/41hCtme7AQ5rsp PodsoHWH/gfa1Fbt9QmGwRjIM04KLoBHQpmiECbBz3g+6LRJ4YfkGhpRTe7QZIFbLGH+ JKqayl8XPz7Stk7eXLPT/KB6A163xlvaydZwEuEw5tln8PZfuCouXuz3CO5LpRH2KTE8 fKVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Sugwskr8rXy42pZ1xDG6/Yn9grQzLU2kaW/tniDjvCM=; b=miKFrEux9Zr3JPVKmBXd7mq3tHxPeRIn9TMW2Qop4S4Ygxp5qyND0rM8eITSEjodd5 jcaLY1YdPMJ3XKz9zMMzTY/23bKWb/yaPJRB4TYqoPsRyqcUPf/Gr9hn89OuyogIYQmA sMChMgMwiorpfL/QtaFO5nXa5Q8XRVCfZXYQSrWgPP7yRta7bTCi7yyjhCy905s6dsnO Hks8FpmCyc1c8mDc9ic/yTZkKmj5tunZsvO/5r5ymHfq5HN4r7bq1cOEIfW202NECyI5 4ZCG6WiOWYHLYWvRze+buiSZfh3W0BACc9Uk+S1hbOfvxBSHH6IWwvaqL569Gz0uay8l kxgw== X-Gm-Message-State: AOAM531ZO3a15qmFArpW5P7BvufuEpqwe7Y72+pWxHJf9t4cSweWzrK2 DUDLql+HHHQWsKZgHsFJr3MUtlHO4w== X-Google-Smtp-Source: ABdhPJy+hre1G5RN1jq0nJSfzX61loPh+welwRzkqIFqp7alxaEk/o/Xx49s2TFsWZg2yfvXi5JrJ0YSHg== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:6273:c89a:6562:e1ba]) (user=elver job=sendgmr) by 2002:a05:600c:35cf:: with SMTP id r15mr12248413wmq.183.1619073899334; Wed, 21 Apr 2021 23:44:59 -0700 (PDT) Date: Thu, 22 Apr 2021 08:44:37 +0200 In-Reply-To: <20210422064437.3577327-1-elver@google.com> Message-Id: <20210422064437.3577327-2-elver@google.com> Mime-Version: 1.0 References: <20210422064437.3577327-1-elver@google.com> X-Mailer: git-send-email 2.31.1.498.g6c1eba8ee3d-goog Subject: [PATCH tip 2/2] signal, perf: Add missing TRAP_PERF case in siginfo_layout() From: Marco Elver To: elver@google.com, peterz@infradead.org, mingo@redhat.com, tglx@linutronix.de Cc: m.szyprowski@samsung.com, jonathanh@nvidia.com, dvyukov@google.com, glider@google.com, arnd@arndb.de, christian@brauner.io, axboe@kernel.dk, pcc@google.com, oleg@redhat.com, kasan-dev@googlegroups.com, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210421_234504_706441_80C39AB3 X-CRM114-Status: GOOD ( 11.80 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add the missing TRAP_PERF case in siginfo_layout() for interpreting the layout correctly as SIL_PERF_EVENT instead of just SIL_FAULT. This ensures the si_perf field is copied and not just the si_addr field. This was caught and tested by running the perf_events/sigtrap_threads kselftest as a 32-bit binary with a 64-bit kernel. Fixes: fb6cc127e0b6 ("signal: Introduce TRAP_PERF si_code and si_perf to siginfo") Signed-off-by: Marco Elver --- kernel/signal.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/signal.c b/kernel/signal.c index 9ed81ee4ff17..b354655a0e57 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -3251,6 +3251,8 @@ enum siginfo_layout siginfo_layout(unsigned sig, int si_code) else if ((sig == SIGSEGV) && (si_code == SEGV_PKUERR)) layout = SIL_FAULT_PKUERR; #endif + else if ((sig == SIGTRAP) && (si_code == TRAP_PERF)) + layout = SIL_PERF_EVENT; } else if (si_code <= NSIGPOLL) layout = SIL_POLL;