Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4061489rdb; Thu, 14 Sep 2023 10:31:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEXWnDP0Kt8SXRBHy5LzkwVqABwJygJU6M1z/7euk511JlCFQX5CxR8CWYI3oDIlPglfIqv X-Received: by 2002:a17:902:c14c:b0:1c0:b84d:3f73 with SMTP id 12-20020a170902c14c00b001c0b84d3f73mr6128774plj.53.1694712681023; Thu, 14 Sep 2023 10:31:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694712681; cv=none; d=google.com; s=arc-20160816; b=jpMcp8BfI8G1aYzGPrIInsLHZ+44j898pXeKVB9n5oJdVbxy38fT56zDi3ClHgxqqM KeMYmpQmVXEjQbZAZGFFdSFy+p2PFbHAog38arqrfr8sox1ERs9G00v29fM4PG0Lq/eB XOMDABtkNUu+JpqUOY3kn+DceWtGUCRg09bZDK5V+0jad/lM/OL59PqaE2+txP+3J4+a Oq+BoMtsujacFAYRmEGR5VoaQ6Bl9XeQeXzc/eeme2tgdvkcAV3Gl7IWiXUojcwAOHwj TCkNT3RV6ynpDmeFf6vrrDishVes6/YYkrrnP6tm+oHO5DVD1vfJegSHEGE/e00IlUph 8Hew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=RJomarRjaTtn3oATFqeS61pqk655aq9C7zKlWCyipu4=; fh=My5njTx3ppUHL/3d+PrD1P/qC+P4OuJ5piwfKibwAQA=; b=jG/U+mqRT0vl2+H0lZ74vTyX2Uq/4Cj15zku5Z1SgKD3Uef5+7dXL0KmjlidxryYIV lNZI78uXN6m9lLdRwGBhes2Z5eP3g7jZ6z7p58gT/UTjPe3jc0SuHpSIl5WwAEZCp+2J b5z6sUQ3LaUeAAwaCUyJgXXAVP34hi+PFJjWlQC+itdlSBCCUtVhQRKGZVG/eEszWFWx lSrrHGQUZX5vdyHmIViEDCFI/gkaZRiqw2luUF9fi5rsJ47JW7PRgDyGbnPXAhBUIfSd TG+4WGWS7nc7QdvEuaufjmrhhdkTvVyc75IWr4MRRCp9vSbV6vmsyALBmtAs1QQXPcoR D9wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=QwlULImn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id i9-20020a17090332c900b001bdc664cd65si2158287plr.165.2023.09.14.10.31.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 10:31:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=QwlULImn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 7ABBA81A447E; Thu, 14 Sep 2023 06:12:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238710AbjINNLz (ORCPT + 99 others); Thu, 14 Sep 2023 09:11:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238790AbjINNLm (ORCPT ); Thu, 14 Sep 2023 09:11:42 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2A1A1FE0 for ; Thu, 14 Sep 2023 06:11:14 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-31c49de7a41so120921f8f.1 for ; Thu, 14 Sep 2023 06:11:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1694697073; x=1695301873; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=RJomarRjaTtn3oATFqeS61pqk655aq9C7zKlWCyipu4=; b=QwlULImn/vm+b+kBqoqtJVxsCj+HpcKUTCrCTVlbAgwC3nyZfjIhiQhCu/IFkUMo2u ori8G1JIyt7SySCOeWp7qfX8wYGLMS6et236HC3gSG6HBGMfdGUCHUwv7EHqxPuX54A+ QPd0TqPCDaWus2VIM9zLP6v1Ye7j5NSFCqisw54hi2ynDDBToETgiFZL3HaWU3tlQYF8 pNOGXko5n69IrsGJuOYATy/qw2Kv2UxA3z7h04z2iDdUU27KIi1Plh/G6XaqQfWkhy1u ySZknfplgeZ3w+pHUrZkbN0WONjKa/tDpe82f6zE86kJSbQnu+lvHQSv2dZwX7M5rv6y 8diw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694697073; x=1695301873; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RJomarRjaTtn3oATFqeS61pqk655aq9C7zKlWCyipu4=; b=seUrthE4AlJcr0m9/fKxzP0dTUZYz7Mx6sBPmUeq1GbZW0GqAjf/DDMsJSASfZ1h+I r6L7IpuMVn01P0fSJSoWKteWwdTXE6chxpVKW7T4vrzN5kKh3uBHdMieMgtbHYicnZov an12QIgbgxohZ8HtptUFDoKIR1AiXwqTcP9ck9GX8EG24I3EacZdsBGdqCFLZtu24Szh lsETqQuTAwQnBZGb4dNRpdCMf5u1IIQrmuo//40Rt5h+97Oc3t4sRfBoum19s8sqemYy vKEeqVtb6DOSmjDmPdEEfjY9o465r9zfWh2BRbSKh4JvnegcqUvDaoyqCPCVvv1ccxm1 3Sng== X-Gm-Message-State: AOJu0YwxO3rKAhp0ic/5W8i8ALy0KgHqYFecYLn5RYp2D5XsY/5X4A0d oJZI8cqSLHqmuHUj5eaJE3oRaA== X-Received: by 2002:adf:fd4d:0:b0:317:3a23:4855 with SMTP id h13-20020adffd4d000000b003173a234855mr4676769wrs.2.1694697073094; Thu, 14 Sep 2023 06:11:13 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:999:a3a0:398c:d142:b5d1:4f7e]) by smtp.gmail.com with ESMTPSA id n11-20020a5d484b000000b00317ddccb0d1sm1747284wrs.24.2023.09.14.06.11.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 06:11:12 -0700 (PDT) From: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= To: Steven Rostedt , Masami Hiramatsu , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , Beau Belgrave Subject: [PATCH] tracing/user_events: align uaddr on unsigned long alignment Date: Thu, 14 Sep 2023 15:11:02 +0200 Message-Id: <20230914131102.179100-1-cleger@rivosinc.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 14 Sep 2023 06:12:00 -0700 (PDT) X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email enabler->uaddr can be aligned on 32 or 64 bits. If aligned on 32 bits, this will result in a misaligned access on 64 bits architectures since set_bit()/clear_bit() are expecting an unsigned long (aligned) pointer. On architecture that do not support misaligned access, this will crash the kernel. Align uaddr on unsigned long size to avoid such behavior. This bug was found while running kselftests on RISC-V. Fixes: 7235759084a4 ("tracing/user_events: Use remote writes for event enablement") Signed-off-by: Clément Léger --- kernel/trace/trace_events_user.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_user.c index 6f046650e527..580c0fe4b23e 100644 --- a/kernel/trace/trace_events_user.c +++ b/kernel/trace/trace_events_user.c @@ -479,7 +479,7 @@ static int user_event_enabler_write(struct user_event_mm *mm, bool fixup_fault, int *attempt) { unsigned long uaddr = enabler->addr; - unsigned long *ptr; + unsigned long *ptr, bit_offset; struct page *page; void *kaddr; int ret; @@ -511,13 +511,19 @@ static int user_event_enabler_write(struct user_event_mm *mm, } kaddr = kmap_local_page(page); + + bit_offset = uaddr & (sizeof(unsigned long) - 1); + if (bit_offset) { + bit_offset *= 8; + uaddr &= ~(sizeof(unsigned long) - 1); + } ptr = kaddr + (uaddr & ~PAGE_MASK); /* Update bit atomically, user tracers must be atomic as well */ if (enabler->event && enabler->event->status) - set_bit(ENABLE_BIT(enabler), ptr); + set_bit(ENABLE_BIT(enabler) + bit_offset, ptr); else - clear_bit(ENABLE_BIT(enabler), ptr); + clear_bit(ENABLE_BIT(enabler) + bit_offset, ptr); kunmap_local(kaddr); unpin_user_pages_dirty_lock(&page, 1, true); -- 2.40.1