Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2397250rdb; Mon, 20 Nov 2023 09:39:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IES52P5Z4KLX4dmnNQ0BaLhkk/S/vul70h8RoUi3VH6aPJO/YrrIpBfcbcRqJegUqleY2eX X-Received: by 2002:a17:90a:d242:b0:285:3486:7fe8 with SMTP id o2-20020a17090ad24200b0028534867fe8mr241997pjw.10.1700501957761; Mon, 20 Nov 2023 09:39:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700501957; cv=none; d=google.com; s=arc-20160816; b=SaIFNnKM/AJoyqkVFIkhzz7Wl4Dxxr6dLeyvjbkDKl60gPgKKQI1XfvzFNrVmUoe9B OsVQtA94XdAo96qv9J8Fc+JLNoZ4nsrXuCDi1XOpQ1dJ/JGLrIDKR0lomQoXX3kDJNKm pRWxr/nHH7F4sjH50BtUkDO/TVXLv15FUkEOAPAKjjSFuY9rj+zIh88kB0uwgMg22ZMa M2idFdOGMKZtqYtW7Cg51FN3Q0DcYc2OecR07tR02QNQ8EbSQy5iFVPFbtcZEmwihtot ri2a3nlLNDnMSQ1dK2iCfxmPk4AdJbea5/N5Aq/LKbc+T3Ik/B40Yd4Nna76so3Vyjfz z74A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=6S4PK8WT3cwW+G2GrOmybB1YODe/+PbVzMA49NRihL0=; fh=EOC++RAGJSrEWP7U4Ssx15/fhuvVfHaHKtOkoE85Ia0=; b=HUqIyNs6OSCuc8JezLE82Y1lOc4zaLcqmnSLhkfmdB//IqnBWeR5OQRpopnKIHzRnW rnzQqGfqwQ/EPavTXBV1bs+XJ3jy7NoLVwHRaht3w4q+S6Xrig7cxQUX9orL0sZv2lJt UDcwphOb8nvsVsXPxh+azn+dOGlawTeqW3jnEjlY7xetF1+TqDL1TruwZh2mtr430PrX gJH+sMet78279Co2yAlvaauo+gkGhFoB5Rcz3DKGCbHNQ0Xs6cgyQ5atlsVZLQAYIC9o bazETu6t22vFPkn64bZm5BigdROIlaBimSYyCNjcaKT4SjEOKZgJQPp319xP+Keqjvdp 2NaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=jfWnXtvP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id bq4-20020a056a02044400b005b82f3dcec6si9396253pgb.269.2023.11.20.09.39.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 09:39:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=jfWnXtvP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id AD946802A712; Mon, 20 Nov 2023 09:37:19 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232103AbjKTRhP (ORCPT + 99 others); Mon, 20 Nov 2023 12:37:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233752AbjKTRhB (ORCPT ); Mon, 20 Nov 2023 12:37:01 -0500 Received: from mail-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15741D7B for ; Mon, 20 Nov 2023 09:36:50 -0800 (PST) Received: by mail-oi1-x230.google.com with SMTP id 5614622812f47-3b6ccaf0516so2764186b6e.0 for ; Mon, 20 Nov 2023 09:36:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1700501809; x=1701106609; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=6S4PK8WT3cwW+G2GrOmybB1YODe/+PbVzMA49NRihL0=; b=jfWnXtvPi63Cju5W8DokCsYXVKltwu06qExZQhXmrNK805rrNt2syRzhkyHNDFWuSz NvW4sr8gfJTysw4g+oS51ZWOEXTkGSjyD26M7Tn6ZultHte+S0N3Tie+MFMjYYcFBFvD 2eHGAjirUmwCgbfu07BZ5kfE4tAyl7J5bjA1x8MpwymukN8OCt6pLS2yytLKu52seIE8 ldLBdfR13qsTtw3e7/XZQ09oLtFLi91ARUs/9KWDF6FCXZue3fUgxrCMoPwFm1hfdous HfzfnBX+D7Ast5rqCFMsYE6mBl2zeSq84e/6kZrc8W6GjElPS05Ta1xtE77i4FRGOPjd jzuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700501809; x=1701106609; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=6S4PK8WT3cwW+G2GrOmybB1YODe/+PbVzMA49NRihL0=; b=GK/YUSVukeOZrMX3GofYNkTC2DkU5VLpjNLYdb8Z8jN+jhUO4SX9CH8nrUzUpzGV6R nwj30TYS6wBs69V1frKx6Z6zalim2wYLV43IzzpyCrA8WSI+maMBdJxVeM8AX0alGY6S KWy0BMcrkj6uid92YKN9jOWZ8RQ16XEL9bHi1ychPhyxrfp02AGVFuomamE9jZ+GFsPW j8xz9lfqBKxb1vssCupA1VtZxImLQbEsskOhXvt8AXaUjX84Q4Ua8C1MYBGTzGRs6Ke+ KEDLJqviHjRvaxMyc7X+5Np12G4xIwQnJRFb/MI5Irqj0HdMHlTZ1HtmgwV9hSKWrMfS jTZw== X-Gm-Message-State: AOJu0Yy7aH7VK68Iucm8B9nspV3sJUjevjzCDTZANWWo2VjCfymvnSaY 4qbYvJxLhHChnDl65tU+24KwpQ== X-Received: by 2002:a05:6870:d3c3:b0:1f0:4e1f:e09a with SMTP id l3-20020a056870d3c300b001f04e1fe09amr116089oag.4.1700501809323; Mon, 20 Nov 2023 09:36:49 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id x55-20020a056830247700b006d64b970519sm1245547otr.2.2023.11.20.09.36.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 09:36:48 -0800 (PST) From: Charlie Jenkins Date: Mon, 20 Nov 2023 09:36:39 -0800 Subject: [PATCH] riscv: Safely remove entries from relocation list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20231120-module_linking_freeing-v1-1-fff81d7289fc@rivosinc.com> X-B4-Tracking: v=1; b=H4sIACaZW2UC/x2MQQqAIBQFrxJ/naA/3HSViMh61aeyUIogvHvSa pjFzEsRQRCpLl4KuCXK4bOYsqBh6f0MJWN2Ys2VMazVfozXhm4Tv4qfuykAmYqd7SvH1joLyvE ZMMnzj5s2pQ90t4V7aAAAAA== To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Ron Economos Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 20 Nov 2023 09:37:20 -0800 (PST) Use the safe versions of list and hlist iteration to safely remove entries from the module relocation lists. Fixes: 8fd6c5142395 ("riscv: Add remaining module relocations") Signed-off-by: Charlie Jenkins --- arch/riscv/kernel/module.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c index 56a8c78e9e21..209db949a06e 100644 --- a/arch/riscv/kernel/module.c +++ b/arch/riscv/kernel/module.c @@ -624,18 +624,25 @@ void process_accumulated_relocations(struct module *me) * - Each relocation entry for a location address */ struct used_bucket *bucket_iter; + struct used_bucket *bucket_iter_tmp; struct relocation_head *rel_head_iter; + struct hlist_node *rel_head_iter_tmp; struct relocation_entry *rel_entry_iter; + struct relocation_entry *rel_entry_iter_tmp; int curr_type; void *location; long buffer; - list_for_each_entry(bucket_iter, &used_buckets_list, head) { - hlist_for_each_entry(rel_head_iter, bucket_iter->bucket, node) { + list_for_each_entry_safe(bucket_iter, bucket_iter_tmp, + &used_buckets_list, head) { + hlist_for_each_entry_safe(rel_head_iter, rel_head_iter_tmp, + bucket_iter->bucket, node) { buffer = 0; location = rel_head_iter->location; - list_for_each_entry(rel_entry_iter, - rel_head_iter->rel_entry, head) { + list_for_each_entry_safe(rel_entry_iter, + rel_entry_iter_tmp, + rel_head_iter->rel_entry, + head) { curr_type = rel_entry_iter->type; reloc_handlers[curr_type].reloc_handler( me, &buffer, rel_entry_iter->value); --- base-commit: b85ea95d086471afb4ad062012a4d73cd328fa86 change-id: 20231120-module_linking_freeing-2b5a3b255b5e -- - Charlie