From patchwork Thu Jan 4 19:42:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13511503 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D5A85C4707C for ; Thu, 4 Jan 2024 19:43:13 +0000 (UTC) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=zFpW4PHq+CvwQcL8l8m/x529BYHyEBdfn/NHHxDjswA=; b=0j2jPSwLc9o5UH hjZ9yT2ci07QspTLCCDxzQZAx1Nh0eWAHRyIBLtA0M+fgamygiWl/nRxU4cczjrbr2qrrE/okAzPs h0n6weIWl6d2r8oSEw7k8DaNw6bLFKc/fi+zhPV8+U8txzelO6kxt7DnA79bQ5fDLAGATK1HoyBXx msHI2+l0vHJJ4LL75OSZ81V2yareQQ2MESw0fQUr2X3oI1WruNjxQ283Fnwae9NqFl23w48EBO2eV H3fQfOSnA75T1db5OUCtFiZtJvnsQ01xy8w1L+zYNKqvHTSQN2dZTOUaVyYd4+m2qb9YmDcc+9PQP Xn+8WyTSDIR6eifWJD9w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rLTcP-00F73q-1e; Thu, 04 Jan 2024 19:43:05 +0000 Received: from mail-il1-x129.google.com ([2607:f8b0:4864:20::129]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rLTcL-00F71Q-0Y for linux-riscv@lists.infradead.org; Thu, 04 Jan 2024 19:43:03 +0000 Received: by mail-il1-x129.google.com with SMTP id e9e14a558f8ab-35fc5f0f9c0so2990435ab.0 for ; Thu, 04 Jan 2024 11:42:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1704397376; x=1705002176; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=tLVjvsKzWbuu1Tn6vfa7DAnWzdMErwoBxrG3TwM6ilc=; b=lJcoaUuFWK/A5bsuFloV5FX5kXNuTcGSmF/s918mNbocfb8Vmlg8FB6Na4MosX/Teo xAZtyrNpxnC75zUzic1Xor9Rja4xx2IuO4x+RCbUZblI5bf8cgtJ20w4TpwzO8M88gS/ MjGXfEVe3vPxmRswcyx2WkOsgwKQlnrI/yuumY+GU+7pp6UUyDkfLt2Dnk5w7LuHqyRd ZkdbB/eU62T/pNl9qva4GMkcn48XKZG+ezh7FC/x6aIFpRecGoXUkhod/pvXmnm9lzWd UGUqacvMb6TuQjAKKPq68D1HyRgtxTLNZY954UqYS/cTt/q0QQGkTvyr/AEWcrlkW4TU sVmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704397376; x=1705002176; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tLVjvsKzWbuu1Tn6vfa7DAnWzdMErwoBxrG3TwM6ilc=; b=hzjcyIIMIUANT8p/eLh+9rT79YCn2P4ryAmF8RK7dm+Paj29KjtbFdGn2+dANYtPOG Z1pn0X3EC0NpoCIXsX/Y+izETcV5iNXMRUmOX6vyCwM3WanM6Zvnp6aeJxQKN1psOE7M 7bAoQVgpbNMglQoy9jwbn8k8ZMRigpMt1fb8BTY86lTD2zUJYyg4KQk+hDH4aZSTHjd/ nOi3kN7PzAAx6hrEIppmFGBONHqYOSX+Jn6Ls1TpU8q3LumXG5bTxSxveKi40aSW109G 20FCMpFomRTZlhanMPmp7jueratKuDWJYNmiIUujVYRtso/XiPSCIj4JQBM5NKwQZXMM vorA== X-Gm-Message-State: AOJu0Yz9oWwGz46/k2QiJMQhkpVxKCAM61A112w0Nz2tG+keO4TUMFOV F7Ytyq31pKx3rsvA1gP/EB2S/fbCGUJ5QQ== X-Google-Smtp-Source: AGHT+IFm+qeZXnh4PvWyj6eeezVL805LTax37/sq68iQqd8SUNlSbsETWbuY1iXc3g3AU1sH94b8XA== X-Received: by 2002:a05:6e02:1be9:b0:35f:e306:cc2d with SMTP id y9-20020a056e021be900b0035fe306cc2dmr1172109ilv.32.1704397376337; Thu, 04 Jan 2024 11:42:56 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id o10-20020a92daca000000b0035d0da89a0asm19606ilq.6.2024.01.04.11.42.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 11:42:55 -0800 (PST) From: Charlie Jenkins Date: Thu, 04 Jan 2024 11:42:47 -0800 Subject: [PATCH v3 1/3] riscv: Fix module loading free order MIME-Version: 1.0 Message-Id: <20240104-module_loading_fix-v3-1-a71f8de6ce0f@rivosinc.com> References: <20240104-module_loading_fix-v3-0-a71f8de6ce0f@rivosinc.com> In-Reply-To: <20240104-module_loading_fix-v3-0-a71f8de6ce0f@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: Palmer Dabbelt , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Charlie Jenkins , kernel test robot , Dan Carpenter , Julia Lawall X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1704397374; l=1064; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=ChQMN8HXWHXJl0z5+9ukmO+5sTC3VuwHdA0xAgdz31A=; b=Nc7YMdNtkiogT9SuSOwkwklZUSWSzuGSMVWI6Jj/7Ki7kHxfugbk8U/yTQtvOO8OlVcnpSpoY O5QMhR5H1UfAHoQ8EspkwAbM3BL/hJ40b6H9Oys/ELv92VYszOq6yck X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240104_114301_214465_237DB22F X-CRM114-Status: UNSURE ( 9.44 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Reverse order of kfree calls to resolve use-after-free error. Signed-off-by: Charlie Jenkins Fixes: d8792a5734b0 ("riscv: Safely remove entries from relocation list") Reported-by: kernel test robot Reported-by: Dan Carpenter Closes: https://lore.kernel.org/r/202312132019.iYGTwW0L-lkp@intel.com/ Reported-by: kernel test robot Reported-by: Julia Lawall Closes: https://lore.kernel.org/r/202312120044.wTI1Uyaa-lkp@intel.com/ --- arch/riscv/kernel/module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c index aac019ed63b1..21c7a773a8ef 100644 --- a/arch/riscv/kernel/module.c +++ b/arch/riscv/kernel/module.c @@ -723,8 +723,8 @@ static int add_relocation_to_accumulate(struct module *me, int type, if (!bucket) { kfree(entry); - kfree(rel_head); kfree(rel_head->rel_entry); + kfree(rel_head); return -ENOMEM; } From patchwork Thu Jan 4 19:42:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13511502 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 79634C47073 for ; Thu, 4 Jan 2024 19:43:14 +0000 (UTC) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ryXD7mVBKIfcqytTfQfk9G/spvNCutjKxZkf2NwBGlY=; b=hsw11x4ZZrYHYg 93pojwxJjT0jg8OY6tQQMpZToA/LYDXSmVce5j8TMkLXGOlGuJXGQisJyFFd0pB2mssFHbNYLzmWh t5lh4ntWTPGkyexBhS4N31mk0j5fCYBdUI+5DZZ07eJeSrMH49xQlmRAN7pRB7Sm9ih+9JoEIZCNm s50kR4sPBFdaRfOquNDZ+uPNXL0CNs40wqjHIXvs2aDYvA5a5qR92MuX1QYjEVRmD+dzs4wvHEieA 2O2Thu/I7fIBuILo9elK8BNRl4chsUPTGzsb8SRdVd/xdSCyv67+iSQ0Fxy5cau2ATSGLl0PtEIgE obJuN4pM6wlkci8HJtSQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rLTcQ-00F74M-2C; Thu, 04 Jan 2024 19:43:06 +0000 Received: from mail-il1-x12d.google.com ([2607:f8b0:4864:20::12d]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rLTcL-00F71S-0Z for linux-riscv@lists.infradead.org; Thu, 04 Jan 2024 19:43:03 +0000 Received: by mail-il1-x12d.google.com with SMTP id e9e14a558f8ab-3606dd96868so407575ab.2 for ; Thu, 04 Jan 2024 11:42:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1704397377; x=1705002177; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=3+J/P1s8879Vp+fzlyGqr2WWOHGZX3A10V1/imIkjd0=; b=H9sxYc7lteH03syRAEH8l3IM5rTRitTbt+vQeynshXMDl/8nos+0uxHPWow/BVz0nv rLIKWfFA3hWt/8L81Yev3K/kCbt8S53X7S0p68/HWEwkkXHpvOEdN9Xnxwx+ag/Tcbg+ F8Pqp2WHGlmzonaFOUvebmui2B20Ztm5VTnXpNPJv6/JSr+CLy3p3PAX8jBCsIfEw+NO SzI/7he2UloTXfyA9eX3Ey3tZmvm89VkHJ0aRXvnmuVEi9Qsa3JVTEjq6qw31fZ4HjCg 2Re8p7/8+ziPUA+Ks3KZU7tT9AX4MWl3gp69D0wcyLCEMkVP0HiM6xcdXbrNpPlbv3tz Ds/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704397377; x=1705002177; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3+J/P1s8879Vp+fzlyGqr2WWOHGZX3A10V1/imIkjd0=; b=p4Ef4g90Q2YYI1PpB/UGRkzwaXM8oRI3DHDJ88MznHWCjCRfdS8Ox2oquroeZ3ce+M guZGFtP+F32j21SYSlO6f1Sw326IT+Jzi2qktMfW4OY6fDks24iN3Ib3G2FQ8mn6XoDq ZQYIzcwH0lszNVPbk00ixY2rwZBFBBUJsDxMu/StgQzVAJljRtro+jdX4+Bvc3di0CTT qylGcA8ZlpUUv4jJPTcFJvV91GVwP5EAP7ba7OovCuiqDyD7/e8LfYY2v46tWsA1FyFg /l8uELqO/zH+sVQqIegmY7k2ffjOVFflRe4b5v50d+48IgeAzqKKRoj7xmQKajC9lOj0 p5rw== X-Gm-Message-State: AOJu0Yzo7u8awnXLHGIGygtOORD+jpmCXQLS4ZrWs5C7DEvi5sGvtsAx W8hIBJCRm9hdgFt9vYgIRWaONY5u4B6M2g== X-Google-Smtp-Source: AGHT+IEcFdfob1Y4RZK+bTpddY/Z8yB4IPD/mUSajVsTBWGnio5958AQpFeVqy17OUHTBH8h9sJFng== X-Received: by 2002:a05:6e02:b47:b0:35f:7d16:c92d with SMTP id f7-20020a056e020b4700b0035f7d16c92dmr934521ilu.44.1704397377439; Thu, 04 Jan 2024 11:42:57 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id o10-20020a92daca000000b0035d0da89a0asm19606ilq.6.2024.01.04.11.42.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 11:42:56 -0800 (PST) From: Charlie Jenkins Date: Thu, 04 Jan 2024 11:42:48 -0800 Subject: [PATCH v3 2/3] riscv: Correctly free relocation hashtable on error MIME-Version: 1.0 Message-Id: <20240104-module_loading_fix-v3-2-a71f8de6ce0f@rivosinc.com> References: <20240104-module_loading_fix-v3-0-a71f8de6ce0f@rivosinc.com> In-Reply-To: <20240104-module_loading_fix-v3-0-a71f8de6ce0f@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: Palmer Dabbelt , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Charlie Jenkins , kernel test robot , Dan Carpenter , Julia Lawall X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1704397374; l=2207; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=9/Y3gMnmhvp1aRf3YmkeyxHlGtG/ubuu7urxufGjwTE=; b=TmjQ+RDNWS877CIosFdTqru/YPzJhO1qbK90hdnM1iOCj2EuiBYwgA4iemJAzXyFiwoJGXHyh u7ieRn45cHtBbE8/eoFg2iQZWB5Lxtlqnoa83kDXjLsS1OHcL+boFcN X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240104_114301_224784_CCB04D4A X-CRM114-Status: GOOD ( 12.19 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org When there is not enough allocatable memory for the relocation hashtable, module loading should exit gracefully. Previously, this was attempted to be accomplished by checking if an unsigned number is less than zero which does not work. Instead have the caller check if the hashtable was correctly allocated and add a comment explaining that hashtable_bits that is 0 is valid. Signed-off-by: Charlie Jenkins Fixes: d8792a5734b0 ("riscv: Safely remove entries from relocation list") Reported-by: kernel test robot Reported-by: Dan Carpenter Closes: https://lore.kernel.org/r/202312132019.iYGTwW0L-lkp@intel.com/ Reported-by: kernel test robot Reported-by: Julia Lawall Closes: https://lore.kernel.org/r/202312120044.wTI1Uyaa-lkp@intel.com/ --- arch/riscv/kernel/module.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c index 21c7a773a8ef..32743180e8ef 100644 --- a/arch/riscv/kernel/module.c +++ b/arch/riscv/kernel/module.c @@ -747,6 +747,10 @@ initialize_relocation_hashtable(unsigned int num_relocations, { /* Can safely assume that bits is not greater than sizeof(long) */ unsigned long hashtable_size = roundup_pow_of_two(num_relocations); + /* + * When hashtable_size == 1, hashtable_bits == 0. + * This is valid because the hashing algorithm returns 0 in this case. + */ unsigned int hashtable_bits = ilog2(hashtable_size); /* @@ -763,7 +767,7 @@ initialize_relocation_hashtable(unsigned int num_relocations, sizeof(*relocation_hashtable), GFP_KERNEL); if (!*relocation_hashtable) - return -ENOMEM; + return 0; __hash_init(*relocation_hashtable, hashtable_size); @@ -789,8 +793,8 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab, hashtable_bits = initialize_relocation_hashtable(num_relocations, &relocation_hashtable); - if (hashtable_bits < 0) - return hashtable_bits; + if (!relocation_hashtable) + return -ENOMEM; INIT_LIST_HEAD(&used_buckets_list); From patchwork Thu Jan 4 19:42:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13511504 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 27E72C47074 for ; Thu, 4 Jan 2024 19:43:16 +0000 (UTC) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8+fCSTlWE4PkNgfM/tJQNeERcgnd3UxH+TOOYgW2OuI=; b=3ShGTK0cjjPAg8 g1aNuSPx0rJ7fdHdOHgqsQSoP96EoGrHR375g9Cz7Unw+Iq67RiWZ+i7xaHoFmsRNDUWmBxASQRA7 SPTNDm024kddDkzcg5OixdVP35YS/PqOHu9zW0k6YuclSTfHd//EyzrCh8ktgogMBs0E9bFWZmvyv pCMjfGdvWL1+FvkUtvJafl+oxM29QbvvOIuOyFUyguice0K72w6GXvO2yCunPqDsW1E0T8iO0gWTM 5mRmwM/BVnQcGg6gGWAsTl9lk3qBtvQg2NP1kz+1VM6q1z/NIcAiWXeTuJ7jFI2laa6yOpvnLTNYb Xjt6NR+5j6WuvZRtXcaw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rLTcQ-00F746-0M; Thu, 04 Jan 2024 19:43:06 +0000 Received: from mail-il1-x12d.google.com ([2607:f8b0:4864:20::12d]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rLTcL-00F71V-0a for linux-riscv@lists.infradead.org; Thu, 04 Jan 2024 19:43:03 +0000 Received: by mail-il1-x12d.google.com with SMTP id e9e14a558f8ab-35fc1a1b52bso3299175ab.2 for ; Thu, 04 Jan 2024 11:42:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1704397378; x=1705002178; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=zwpW8R3xYRcFeijiUFHaM884VPc1V+tX+SXLWnbPyzE=; b=vhBJtMQumhHUtxCyS/rHJHhsrYbzkgzYPVwax41GuYQkXjGeOc7zdBeqGHOw80SIBf RaG3ByEjHQlvgyEF3hU2qiTIzrf5NIZzUxlB9SZpPX1Jf7MNmfwdtOaQhwaxb12YquAL JbP4HXMIq6+iwAaU8/JywwEX8WnoYxkOCKWRtxgilzlRKwS7o2hA6vGI5EzSL4fF3bzY mnzXti38gq5c0cA1wH949qGcrzXRf7BIv0Pnfyy1iKrESbxaCf8RSJPYXv0G3Lk+ScPZ hApcXovsxwwH9j6wnNMKgTBl55UbyB5zjZ5qca6fktiTvUmJeGlzLxIDc+oJ3KSJx3ew mpyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704397378; x=1705002178; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zwpW8R3xYRcFeijiUFHaM884VPc1V+tX+SXLWnbPyzE=; b=L0cW+AfJTRLb3X5sWeHWQpGR/x7LK4PHs6mRXWuwIEKu81Vg4+3tpWHT7rafPFiITI k9i6EMNXPJLabrZpD8Uz2zUXpQ612BCmMkHtag0RydbHgdySoKTZ7TUOamlAbuMwpRw6 xgGXnsP1ncmNwALfCE2o2I58xAdQ8lxnAnzD6Lg2DEiRCjbxMtaY/gpOg6vW8IBSK1o+ gFcztRJIw3tsbw0AucAY5bzxYdPvOSDf+OSlxE9EFWP4MkQb5QNd1YRgzEntfZGovaT0 NwMZqtmX0Oc0XwGjoyooWQ9iVM3A/UFeRl9e1ld7OAAW+M8oAD3lixmJfco+/m9/yrdm htpQ== X-Gm-Message-State: AOJu0YxAs3SCQuryS1LwySiYLr5xHPXSaJVsQn/1Nv72Vc8dk0U7CNby b/GEWvRBqtTIO8dD59h79HTOY+BzRVnDGA== X-Google-Smtp-Source: AGHT+IHT5RafxhxVkhoC7ZCG7auu1NWdb7RZx+i84274U3eQ2c8mka4bV5n112vi+aMJBdUfbRUZxQ== X-Received: by 2002:a05:6e02:170f:b0:35f:ca3f:fa67 with SMTP id u15-20020a056e02170f00b0035fca3ffa67mr1224476ill.43.1704397378523; Thu, 04 Jan 2024 11:42:58 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id o10-20020a92daca000000b0035d0da89a0asm19606ilq.6.2024.01.04.11.42.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 11:42:58 -0800 (PST) From: Charlie Jenkins Date: Thu, 04 Jan 2024 11:42:49 -0800 Subject: [PATCH v3 3/3] riscv: Fix relocation_hashtable size MIME-Version: 1.0 Message-Id: <20240104-module_loading_fix-v3-3-a71f8de6ce0f@rivosinc.com> References: <20240104-module_loading_fix-v3-0-a71f8de6ce0f@rivosinc.com> In-Reply-To: <20240104-module_loading_fix-v3-0-a71f8de6ce0f@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: Palmer Dabbelt , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Charlie Jenkins , kernel test robot , Julia Lawall X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1704397374; l=1020; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=js9HmT4o7o8yl7lcSP3vcOE6sOgYhIQV9xZrhoMilzw=; b=oUTjSCnJ23EEXgoFiAFQOCyorLMnwVgQFC3OVXHU3L3GlTodRKu31Mb8jIU/r+O//70Beb63d HTFAbKyU+gjDCurro3YjGZ65fM4ysi2YV+LUAPTAIcM8RdGWr0teXfJ X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240104_114301_222523_6CB8E99F X-CRM114-Status: GOOD ( 10.67 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org A second dereference is needed to get the accurate size of the relocation_hashtable. Signed-off-by: Charlie Jenkins Fixes: d8792a5734b0 ("riscv: Safely remove entries from relocation list") Reported-by: kernel test robot Reported-by: Julia Lawall Closes: https://lore.kernel.org/r/202312120044.wTI1Uyaa-lkp@intel.com/ --- arch/riscv/kernel/module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c index 32743180e8ef..ceb0adb38715 100644 --- a/arch/riscv/kernel/module.c +++ b/arch/riscv/kernel/module.c @@ -764,7 +764,7 @@ initialize_relocation_hashtable(unsigned int num_relocations, hashtable_size <<= should_double_size; *relocation_hashtable = kmalloc_array(hashtable_size, - sizeof(*relocation_hashtable), + sizeof(**relocation_hashtable), GFP_KERNEL); if (!*relocation_hashtable) return 0;