From nobody Fri Jun 12 09:56:56 2026 Received: from cstnet.cn (smtp21.cstnet.cn [159.226.251.21]) (using TLSv1.2 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ECEEE37D11F for ; Sat, 9 May 2026 07:40:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.226.251.21 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778312459; cv=none; b=uPSIVSJGuNAZWytMem1Yn9Bk6f8LCwz8dNnMrxw6kTjWjmxzdOz1Fg3PP1/rj9JcSjQS9+KdMOANfCqb9TXOd68fvBGI/lRXD0N8nA3V8INM9qillyDivmSa7YxMdNw3g2P9/6LxWDuTNVfNFNSJXlsWPQPSESCtvw12pb/TGGc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778312459; c=relaxed/simple; bh=B+xiAvfWoukKHAy/ekWnCvVH5Nycx6cGxuDIpuRMCSA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=PKfrQFOoHjyiuJevOptA1sTh29GYOlSro4DxQRjzj8Jc9WWW/DX0XiiodO8X5tBi0jyisI8AAZZ85dQv7f4BuZ+yMfTJIwGBgcq3c2c+eVSvgzF88S+7AayrJtzga6iCxvp/MWWHx+S6s+k0tI6028ds6D7dTfmrZjgD3JnJqs0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iscas.ac.cn; spf=pass smtp.mailfrom=iscas.ac.cn; arc=none smtp.client-ip=159.226.251.21 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iscas.ac.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iscas.ac.cn Received: from yzs (unknown [115.199.218.204]) by APP-01 (Coremail) with SMTP id qwCowAC3Xmr_5P5p0eyvDw--.12791S2; Sat, 09 May 2026 15:40:47 +0800 (CST) From: Zishun Yi To: pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: alex@ghiti.fr, kees@kernel.org, charlie@rivosinc.com, Zishun Yi Subject: [PATCH v2] riscv: Check the return value of reloc handlers Date: Sat, 9 May 2026 15:40:46 +0800 Message-ID: <20260509074046.1747927-1-vulab@iscas.ac.cn> X-Mailer: git-send-email 2.51.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qwCowAC3Xmr_5P5p0eyvDw--.12791S2 X-Coremail-Antispam: 1UD129KBjvJXoWxJF1ktw43Ar4DCrW7Gw4fuFg_yoW5GF13pF ZxG3sIyFWkCw12gF48t3Wvgw4fCa1kWr47WrZ0gw4SywnxCr1rt345tw1YqFn3Wr929FWU Xr1j9F1UCw4UArDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkG14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26ryj6F1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4j 6r4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY1x0262kKe7AKxVWU tVW8ZwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14 v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkG c2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4U MIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUpwZcUUU UU= X-CM-SenderInfo: pyxotu46lvutnvoduhdfq/1tbiDAUCA2n+2sIcQQACsY Content-Type: text/plain; charset="utf-8" Currently, process_accumulated_relocations() ignores the return values from both reloc_handler() and accumulate_handler(). As a result, the kernel will proceed to load the module with corrupted or incomplete sections, which can lead to unpredictable behavior or kernel panics. So we need to check the return values of the handlers to propagate the error, and fall back to the cleanup mode. Fixes: 8fd6c5142395 ("riscv: Add remaining module relocations") Assisted-by: Gemini:gemini-3.1-pro Signed-off-by: Zishun Yi --- Changes in v2: - Added 'Assisted-by' tag. arch/riscv/kernel/module.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c index 1961135689db..b6512fa9aca1 100644 --- a/arch/riscv/kernel/module.c +++ b/arch/riscv/kernel/module.c @@ -594,7 +594,7 @@ static const struct relocation_handlers reloc_handlers[= ] =3D { /* 192-255 nonstandard ABI extensions */ }; =20 -static void +static int process_accumulated_relocations(struct module *me, struct hlist_head **relocation_hashtable, struct list_head *used_buckets_list) @@ -625,6 +625,7 @@ process_accumulated_relocations(struct module *me, int curr_type; void *location; long buffer; + int res, error =3D 0; =20 list_for_each_entry_safe(bucket_iter, bucket_iter_tmp, used_buckets_list, head) { @@ -637,18 +638,27 @@ process_accumulated_relocations(struct module *me, &rel_head_iter->rel_entry, head) { curr_type =3D rel_entry_iter->type; - reloc_handlers[curr_type].reloc_handler( - me, &buffer, rel_entry_iter->value); + if (!error) { + res =3D reloc_handlers[curr_type].reloc_handler( + me, &buffer, rel_entry_iter->value); + if (res) + error =3D res; + } kfree(rel_entry_iter); } - reloc_handlers[curr_type].accumulate_handler( - me, location, buffer); + if (!error) { + res =3D reloc_handlers[curr_type].accumulate_handler( + me, location, buffer); + if (res) + error =3D res; + } kfree(rel_head_iter); } kfree(bucket_iter); } =20 kvfree(*relocation_hashtable); + return error; } =20 static int add_relocation_to_accumulate(struct module *me, int type, @@ -886,10 +896,8 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const char *= strtab, return res; } =20 - process_accumulated_relocations(me, &relocation_hashtable, + return process_accumulated_relocations(me, &relocation_hashtable, &used_buckets_list); - - return 0; } =20 int module_finalize(const Elf_Ehdr *hdr, --=20 2.51.2