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) {