From patchwork Tue Apr 9 10:02:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 1921323 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=rDYBB/6C; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=itnejEM+; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VDM2z2t6Kz1yYH for ; Tue, 9 Apr 2024 20:02:51 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=X6Y0DZ8gXi+OKxDTOWsP+h1/eILryvfAYrNScMIb6ec=; b=rDYBB/6Czen496 T2ITtn6xMhWe753HwVDcQJAtfOyBjnpTpAmTvrDpgfsdPsP7piQTeoXViUbYuH+e/tkhN4G7J5JGM RbE8Ii9tGfQqkpLQV7+zMXe+VZA3CrOHCmmKYYYvaFS5VvRKjnOgcfzQmK6U3Iggk8ZZgrfXNUPXO DAW+QK3TaRn12H19Y3HVX0rD+XVcg3HELgWwPIRkd6TwUSoNYP4jjL/cvy5Ezf2N+TP6X0a29WC68 qUPpNci89DJwpEqZVVs8B/RgnjBGZUbHLgJaZ5DCQn4EUAw/iptut/xwPSxfGDSArsb1sTaP0i7f2 4quungj70xQ8LiCd7Jrg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1ru8JR-00000001KZC-0d5N; Tue, 09 Apr 2024 10:02:45 +0000 Received: from mail-wr1-f50.google.com ([209.85.221.50]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1ru8JH-00000001KPU-2asT for opensbi@lists.infradead.org; Tue, 09 Apr 2024 10:02:38 +0000 Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-34560201517so623504f8f.1 for ; Tue, 09 Apr 2024 03:02:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1712656949; x=1713261749; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nQuNxHzEf4hr+JBIDmx3DrbTSwDj6VZpTrpjj7OdJ9s=; b=itnejEM+WaLGb7O27q7+77DTO8m7ltszHc3232EqJLm3bn58KIFMHAbhC8/SwahJAP T/qQLundqs0kwFWr8+TVyJOl3twX1tk1MfalZF7I76ULsbF9b65mrHaRiVNNP9IXB3mu 0bYrNnf44WZPP4RDn4KwmyjvC/P/VH78qWZWtPASMJnilWcpsv/wswmksYf0U1MAuiqe JVyzCnFmRP8OJQ+jat6i8aU2CMgMvxj/eMbv09ZMV0rmXyTz8iA7LKaZKYVElgEvVTfl i+oZjSUPHdlhnLjQ9lrZUr204Tu3uo2RNbx17NqejleJAi4IuMf3F+GlN++x945siHOC Xr/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712656949; x=1713261749; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nQuNxHzEf4hr+JBIDmx3DrbTSwDj6VZpTrpjj7OdJ9s=; b=fJvDqj0KyVtqAx0ITB17sUeGNmAzSeb9w6MSRJuNBy3ByEkxY66owzpmht7Km9HO09 MUm7s9tm/rGsCsKVuyi9T91PYqnf+mTNjZa+gV/t1bhxhqQCnmgzTP3sRyLUnV4Oy2BG msDdHv2MSaOQaHmnOSdB7JWoFNGmsMxmksO8GO011eNRUhUuL07TmR7G+bg0Ud3EcePz FKkqAtb4JtGlS6JLzj4XZJVNxnOTK8i7ogBwPMV5nfAvsK5xWvY5dsQIm4HeZTlO+hJh gxErScCoGrzvJk6WNMJtpPo02w/q7o9KhBI5QRhQiPou7W7ywxLvYRAR+G//48YxuMQP 1wgg== X-Gm-Message-State: AOJu0YxS3ov/Zo6J2t3asBwv+FpqtXuUJsQKVXAp1X8EEGeKIhvzD5V6 4qVhecv4Rr3Oerzpw4JZvIyrA2int1drjvmDa14vaRHsIoGMlnexOnSl942fyJUnDF214Pw7MiE lHb4= X-Google-Smtp-Source: AGHT+IHOyl4DvXMM0h5B0Rm1Q8zSSGiwCja/qGjdbkF6l/2cRJApXAxFaD6bHl9ChBQNnie4O/eglQ== X-Received: by 2002:a05:600c:198f:b0:416:b9c3:c691 with SMTP id t15-20020a05600c198f00b00416b9c3c691mr9750wmq.4.1712656949291; Tue, 09 Apr 2024 03:02:29 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:999:a3a0:322c:7eda:35fd:4614]) by smtp.gmail.com with ESMTPSA id a20-20020a05600c349400b00416b28651e1sm862972wmq.36.2024.04.09.03.02.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 03:02:28 -0700 (PDT) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: opensbi@lists.infradead.org Subject: [PATCH 7/7] lib: sbi: sse: check handler entry to belong to supervisor mode Date: Tue, 9 Apr 2024 12:02:08 +0200 Message-ID: <20240409100216.263256-8-cleger@rivosinc.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240409100216.263256-1-cleger@rivosinc.com> References: <20240409100216.263256-1-cleger@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240409_030235_828098_A2F8D4C9 X-CRM114-Status: UNSURE ( 8.46 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.0 (/) X-Spam-Report: =?unknown-8bit?q?Spam_detection_software=2C_running_on_the_sy?= =?unknown-8bit?q?stem_=22bombadil=2Einfradead=2Eorg=22=2C?= =?unknown-8bit?q?_has_NOT_identified_this_incoming_email_as_spam=2E__The_ori?= =?unknown-8bit?q?ginal?= =?unknown-8bit?q?_message_has_been_attached_to_this_so_you_can_view_it_or_la?= =?unknown-8bit?q?bel?= =?unknown-8bit?q?_similar_future_email=2E__If_you_have_any_questions=2C_see?= =?unknown-8bit?q?_the_administrator_of_that_system_for_details=2E?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_Content_preview=3A__When_registering_an_SSE_event=2C_check?= =?unknown-8bit?q?_for_the_handler=5Fentry=5Fpc?= =?unknown-8bit?q?_to_belong_to_supervisor_mode_domain_using_sbi=5Fdomain=5Fc?= =?unknown-8bit?q?heck=5Faddr=5Frange=28=29=2E?= =?unknown-8bit?q?_Signed-off-by=3A_Cl=C3=A9ment_L=C3=A9ger_=3Ccleger=40rivos?= =?unknown-8bit?q?inc=2Ecom=3E_Reported-by=3A_Samuel_Holland?= =?unknown-8bit?q?_=3Csamuel=2Eholland=40sifive=2Ecom=3E_---_lib/sbi/sbi=5Fss?= =?unknown-8bit?q?e=2Ec_=7C_6_++++++_1_file_changed=2C?= =?unknown-8bit?q?_6_insertions=28+=29_?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_Content_analysis_details=3A___=28-0=2E0_points=2C_5=2E0_re?= =?unknown-8bit?q?quired=29?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_pts_rule_name______________description?= =?unknown-8bit?q?_----_----------------------_------------------------------?= =?unknown-8bit?q?--------------------?= =?unknown-8bit?q?_-0=2E0_RCVD=5FIN=5FDNSWL=5FNONE_____RBL=3A_Sender_listed_a?= =?unknown-8bit?q?t_https=3A//www=2Ednswl=2Eorg/=2C_no?= =?unknown-8bit?q?_trust?= =?unknown-8bit?q?_=5B209=2E85=2E221=2E50_listed_in_list=2Ednswl=2Eorg=5D?= =?unknown-8bit?q?_-0=2E0_RCVD=5FIN=5FMSPIKE=5FH2______RBL=3A_Average_reputat?= =?unknown-8bit?q?ion_=28+2=29?= =?unknown-8bit?q?_=5B209=2E85=2E221=2E50_listed_in_wl=2Emailspike=2Enet=5D?= =?unknown-8bit?q?_0=2E0_SPF=5FHELO=5FNONE__________SPF=3A_HELO_does_not_publ?= =?unknown-8bit?q?ish_an_SPF_Record?= =?unknown-8bit?q?_-0=2E0_SPF=5FPASS_______________SPF=3A_sender_matches_SPF_?= =?unknown-8bit?q?record?= =?unknown-8bit?q?_-0=2E1_DKIM=5FVALID_____________Message_has_at_least_one_v?= =?unknown-8bit?q?alid_DKIM_or_DK_signature?= =?unknown-8bit?q?_0=2E1_DKIM=5FSIGNED____________Message_has_a_DKIM_or_DK_si?= =?unknown-8bit?q?gnature=2C_not_necessarily_valid?= X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Atish Patra Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org When registering an SSE event, check for the handler_entry_pc to belong to supervisor mode domain using sbi_domain_check_addr_range(). Signed-off-by: Clément Léger Reported-by: Samuel Holland Reviewed-by: Anup Patel --- lib/sbi/sbi_sse.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/sbi/sbi_sse.c b/lib/sbi/sbi_sse.c index 85137c2..8724f76 100644 --- a/lib/sbi/sbi_sse.c +++ b/lib/sbi/sbi_sse.c @@ -959,6 +959,12 @@ int sbi_sse_register(uint32_t event_id, unsigned long handler_entry_pc, if (handler_entry_pc & 0x1) return SBI_EINVAL; + if (!sbi_domain_check_addr_range(sbi_domain_thishart_ptr(), + handler_entry_pc, + sizeof(unsigned long), PRV_S, + SBI_DOMAIN_EXECUTE)) + return SBI_EINVALID_ADDR; + e = sse_event_get(event_id); if (!e) return SBI_EINVAL;