From patchwork Wed Jan 3 20:22:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 184842 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5244870dyb; Wed, 3 Jan 2024 12:24:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IG/MPGGmHtIFNfUAvaUca5TqvziUOmHiWS+FGa1+n9bPrCvSqY87/OgYks/FLne+u1CyefQ X-Received: by 2002:a17:902:a507:b0:1d4:9dd9:9ca3 with SMTP id s7-20020a170902a50700b001d49dd99ca3mr3675505plq.82.1704313489137; Wed, 03 Jan 2024 12:24:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704313489; cv=none; d=google.com; s=arc-20160816; b=Q06TgQwT82wR1clgSU26xenSBsIN7j1kfxTeHveI9QyIenwOvOxieP8xIlT2kB74rC LXHnZp9nzKDPaaPeAwlND2k9PDdllaA5ZMPw+ZViZiWDZLulK6Lou/Uxe9A+1vBXFeov shjK4oCjOJyJ3vyRz8TzIlYl+V009TU4PVhHH7wXcF1wrGLIoeOByFH5cvmVYPEdRs2z HB47Bvz7CTxUGhrQxEzXoIJFyZ+l1p+e6m2/On9OYjlCUJhPbNg8Youyr3YiCVovhRG7 W1VfL8gAlo0PxdyqpVahGiDRWxrbYwhmnv5NOhp20UNNp0K6Drn/9t2oRtv/+0fUvNMT IhnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=tLVjvsKzWbuu1Tn6vfa7DAnWzdMErwoBxrG3TwM6ilc=; fh=Ahh0xTAUL1AgDekyVcpw69j+dWAVbMNIcavoTh8jol0=; b=vklseodeN+EyxS5tQaWHnQQ8RcETzfdOee16s/gwiT4o61bZITXm9sqsEWXV7voqKD WD6I1nklzz/3a4PwBsFUdR8N7lBOSC6hT/hrzoWHsYNcGfviQzJuNb23i7FgFkuL7LSh ULhaVWjKJaLy6c0Ux2Ooh45Ttl1QZnMxQweIyp/oAdbjvKFKulS9iXZ0UUpynEzleCKx rRRMEEtdPAwfda7oIf05R9oKolnXVHMmkGbD63AqCYllDq8g60NYBdNUOSVRcTPG6GGq ipYwWdv7gJ3xeibkbjLuxuEjuKjCh5U6xpXwVqOMpc4qMkJpZytjv7kqdgOABsRH0qRW 1Vxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=NBk189ic; spf=pass (google.com: domain of linux-kernel+bounces-15972-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15972-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id l7-20020a17090270c700b001d4a4ed999csi8100640plt.531.2024.01.03.12.24.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 12:24:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-15972-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=NBk189ic; spf=pass (google.com: domain of linux-kernel+bounces-15972-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15972-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 5CACBB2238F for ; Wed, 3 Jan 2024 20:22:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 335681DA4F; Wed, 3 Jan 2024 20:22:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="NBk189ic" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E261B1D522 for ; Wed, 3 Jan 2024 20:22:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1d3eb299e2eso52717895ad.2 for ; Wed, 03 Jan 2024 12:22:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1704313324; x=1704918124; darn=vger.kernel.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=NBk189icOCbpjEiyIHfGUJaUW2XTJ7RuibADJ2XFiRXBXMJ75ORsfQWil8q13vlI9I 0Mrxg1/oAolHp5QCv3RNgjRPbNzNxVwU8tGaucOOnjcrQ+ds5QC8CaJmfgnAhI7Wmqkl 5me2OFIYC050i4/7ySoGGNKcrW1bINZm55c1t1BzRjat2z37/EMyR3mwVe9Zb0NPfTU+ NUx0gCPLWEHDe5AHdhm+YHl1ADcdYDTnD/0W7LyqONYxiVwxZ7NaJuqXeWubB5C3KGR8 0GJIQN08NCMHxzk7QZneELB1lvdMd/7VMmeHm/MYHPS5IxJcPdaK3GDrJr04uPMaxKUw 1j5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704313324; x=1704918124; 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=cYrkOg2wcmusn0rD3IgsM5v3qRB/4nD3drB8LMrqZNJ9o5+dsRn+wHVhPhq38RonQt e6wsn1VN7ogizMDS95/BHLIdD/UT9GA/gvxn642ybSVONREPI8V3hUsCHJgTz37SEVs5 FhZ+WLL7I+uz+VF+l8JequzFocdZjZngmURC70HsKCRSkSTrb+I5VxOEXSjsAPtCniE5 mt6c8IM8rwlOEqu/FIsE14c6S3zWc65ydrtQNzm3V9yZpi1rztW/DTLMvC86HbrF/xRZ Ryv0LTPjwaY24IYNptnX90SvA6j2deZn1sM73SxujO4oE1XTpflJ3tl1rSosVfgskUb3 T7pw== X-Gm-Message-State: AOJu0YwI61Q/b6p0AnhihvpXwJD9m4yl4R+Eu2o4IQSaQJwGcNnnkJFl Jl9AqAgFq0ZJhKJ/qOxfhSojw7OZ6jNqvQ== X-Received: by 2002:a17:902:e544:b0:1d2:fa24:2266 with SMTP id n4-20020a170902e54400b001d2fa242266mr10957069plf.6.1704313324207; Wed, 03 Jan 2024 12:22:04 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d13-20020a170903230d00b001d3fa5acf71sm24278739plh.12.2024.01.03.12.22.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 12:22:03 -0800 (PST) From: Charlie Jenkins Date: Wed, 03 Jan 2024 12:22:00 -0800 Subject: [PATCH v2 1/4] riscv: Fix module loading free order Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-module_loading_fix-v2-1-292b160552c9@rivosinc.com> References: <20240103-module_loading_fix-v2-0-292b160552c9@rivosinc.com> In-Reply-To: <20240103-module_loading_fix-v2-0-292b160552c9@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=1704313322; l=1064; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=ChQMN8HXWHXJl0z5+9ukmO+5sTC3VuwHdA0xAgdz31A=; b=eGXoLh3RaVKJ+iWJ01D8+xrpOG2nvatttc/x3QBl+mQVjpXaGPIZMjUPquFofeleKnCdAjlgc stOmeal7/ylCU+9I0MA0q1qU3cXe7vaOsm6yfJVVzZ1gEdWsFVIIwEn X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787102221424462069 X-GMAIL-MSGID: 1787102221424462069 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 Wed Jan 3 20:22:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 184838 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5244136dyb; Wed, 3 Jan 2024 12:23:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IFFEndBjGvLnm5dO34hGbz05u5o7tucXYEAmUUUvvUonPZmVett1SofCzv8HmlpUfNegJzI X-Received: by 2002:a17:906:fe0a:b0:a28:9ec6:2fe5 with SMTP id wy10-20020a170906fe0a00b00a289ec62fe5mr658135ejb.77.1704313393107; Wed, 03 Jan 2024 12:23:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704313393; cv=none; d=google.com; s=arc-20160816; b=Jgtz47RJQgEgjwOAZ/glpiuFmjewXUhrmHGD/tWhLKapgjjoUeWvhIuLbySUOtoE4L SHK3KhAULksDVWXfQVb6y640bLVj/FcDv2RmA6MFcnVrqrwoXmwnhj3cxOTZmOhgG7dK lgPLU2wgywew82Adph/a8UbgVK1io51oAueQQxmu0hOwxK1/N5NKz7kEBL0avHfwPuJf WVG2Krmay6Nx5vmItuJs+RH35rJDKZT91zBDCLRvgnJD6PVZdgCvGp4p5HcAgSshHat5 PteZO8PaACR8cKGgLB5NlaiH5VJGX919CD0xJbV4Po3jKA/SiYZg3SbPoxqqGIkT9G5I w/Qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=3+J/P1s8879Vp+fzlyGqr2WWOHGZX3A10V1/imIkjd0=; fh=KGTjH/kFRbYmCBGAqhwqn/PsFe0lEsOMEs0opiHr1Wo=; b=eZMrR7Zdlbqp5ttULUoyS60jzWN6wFw8nimQSaid2Llxj8f0DrenTWaeRnr4D9NrFc 84kIDNEIOM9ZBYkZ4Ip0YPpa2bfeCEWThrZX5KombuxancFEXjGgnGmhurMElDkTcC8H 5YWCtDuSa3OymcvrXo4c0c7His7YUKrN4qaHQg9cz/PRjP0ujIwQCfO+F7amoujyeLgI l9hKSwefKFlJZueg8WlGsaxkflXB8Uo/c20dU+B4KtA11cELOeTc863aNXWVI2/VVzA2 EEM8/Q/D7PchnWK+8b2AKr+OqIiDM5qIoVMlDIJRTtrNCIlskiLX6zUoTNsvfGJ5HnkL +f6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="FLV/hZyk"; spf=pass (google.com: domain of linux-kernel+bounces-15973-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15973-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id vl15-20020a17090730cf00b00a2352b26d10si11975497ejb.368.2024.01.03.12.23.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 12:23:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-15973-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="FLV/hZyk"; spf=pass (google.com: domain of linux-kernel+bounces-15973-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15973-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id B3E6E1F22431 for ; Wed, 3 Jan 2024 20:23:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 075011DDDA; Wed, 3 Jan 2024 20:22:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="FLV/hZyk" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2E561D52D for ; Wed, 3 Jan 2024 20:22:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1d3f29fea66so45576105ad.3 for ; Wed, 03 Jan 2024 12:22:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1704313325; x=1704918125; darn=vger.kernel.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=FLV/hZyki3DS42L108bYaVqELfYGcoo38cDngIFDoqnBaGHXW8JJH/KAZlPL+gqC+q ROkTAoHqB1Jd6qRDW1VEcWVjrz6pRBcM/HNiNSH0uXRK7izlEFaTozPsXBOdLbu5kiEp R1N9/tf9C+hD2JHLitFdbfmNcs/En99/rKKoK7G8WEApCBWxKyTIkvZem9P0khVsIZYR 5HW8cFILBXlYKvQGxXzfjgGHYF3tjsIxdI0ojDJ3Fpdrxu02I/INzW0ugGI6OEW+yhZO bfYbpSKF+g8YUaQ6lUU4y0i46+uxCe8P+iKIef7lh8euEA/MfkOcE3t9JJuhyQ9IcK3K pDLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704313325; x=1704918125; 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=rMtSniqRx39s254Q8nV6QZF4IEVbfbi+h27L+W+wPYxV3/lzneW/1D3GFv3AMIKsKr Sn2KSjJaSf4r7vyc6pQ5bSGJgelSdB/Q2b+47uL/beta3r/uwC6Svu/fLtU+5xvofsoH 7dFd8kGW5qhzVY389BaW8Ev/s5kewsEJNNvF9kBigQvkqZY5yhsM5ez7IT/m4mMhC4KN 4o5u23Gglr9BUfS5dq2G/j8n6S946v0nvBRjeiOnptznQ4Mf5h0irTI/dayo2zc01AXi vdWKskun8webuB3VAY6yVZ8UVK6NuCoZM0t7uzr9xN4FJfPlvqRtwlzgG+kk16+m2vdI uytQ== X-Gm-Message-State: AOJu0YwtpZT2gHbcMS/FgqBHok5g1ldoE0uhoHvtmlZlUxuz5htqJMS6 NF+d4CLCiuMiOzanqY/OdkcxIc1pY4l7Bg== X-Received: by 2002:a17:902:da81:b0:1d4:c2ad:8ff8 with SMTP id j1-20020a170902da8100b001d4c2ad8ff8mr2710218plx.34.1704313325161; Wed, 03 Jan 2024 12:22:05 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d13-20020a170903230d00b001d3fa5acf71sm24278739plh.12.2024.01.03.12.22.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 12:22:04 -0800 (PST) From: Charlie Jenkins Date: Wed, 03 Jan 2024 12:22:01 -0800 Subject: [PATCH v2 2/4] riscv: Correctly free relocation hashtable on error Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-module_loading_fix-v2-2-292b160552c9@rivosinc.com> References: <20240103-module_loading_fix-v2-0-292b160552c9@rivosinc.com> In-Reply-To: <20240103-module_loading_fix-v2-0-292b160552c9@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=1704313322; l=2207; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=9/Y3gMnmhvp1aRf3YmkeyxHlGtG/ubuu7urxufGjwTE=; b=oEe24hSZfsF4mLEENjvlrgBmLszzS6CujSYHcb5xYW5WEK65TSlLI3Drvqi0xuE88wUYf0yle tAaS12iJPF5DN1hbXifh/mprzWl2DKH2wdFUJ5myCBMAR510KON/qKu X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787102120461933911 X-GMAIL-MSGID: 1787102120461933911 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 Wed Jan 3 20:22:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 184839 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5244236dyb; Wed, 3 Jan 2024 12:23:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IEzxTsYroS2W5ecROJwPskaumAilXepBpK1nkPhnUwHmbO1Mi/pCGMFmLAyV4NQBTO/EKE3 X-Received: by 2002:a17:903:1211:b0:1d4:52f6:e046 with SMTP id l17-20020a170903121100b001d452f6e046mr2114959plh.58.1704313406745; Wed, 03 Jan 2024 12:23:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704313406; cv=none; d=google.com; s=arc-20160816; b=KZJxJtlCMYDS1F5yOR5b6/Tv9wkDN6oWT1T6ZM7ZgcpvzF/O7Gat/6uaCTMyfvcZoD RCG/QEBUxTkNL9+SHJhtSllF6YgyaNASPB7q8Nz11LBihPPISkH5NLbBJf/mHPgq9yxw Pbd+mATrNat9DVNw+lptabWyRv5Wu8db4m67cylOvN4J+ACXsO0f5Am/+61wkYXuxGgE NTI0h4shmXY+QgX1r3jvLF88CWUwyaNk3qUfHUGSgUvooH+OpSdLrsL16xNEBdpbiGCl 3sre7No1Ak8CDa76NkXKH2JGD6TScoow3CrE8RGrdNPUEvwCZG5NXCVlE2Vnwvjw8rG9 gqWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=zwpW8R3xYRcFeijiUFHaM884VPc1V+tX+SXLWnbPyzE=; fh=31PALnH5Cq0q1EcVShuOPRZ2lq7PUU43EKkNLu2N57Q=; b=y21oCAUYmliISjPi6JtDzX4llZ95iXWI8VzSYyFLq5OWs27/I60+CaIKMVX/1Hom8M L0S0U+Bm7A+whl7AVigWJJJWzGc7CF5EeaQXRQ/R/HpSph8J+MJ/ZOZb6Ie4GbCx+WdK hzB32FCT/AguDkAsRKL4yiNTHFKtYLSbjYmzuHt7FJrAU0zgROycleHPco+rdeMWkm+v 90PHVnIUzOElndXly7hz0AJXE/kd+SyKvNrb9WMxa2+Va8ikzq3uif2I/O3naj9H6BNn JiLtlvVOnhYwhNYwHNtQZGcui4E300g0Y4110Hq+F2GuosFyNLX4BPg8RpG6BLB+9cRp th1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=FvoiyVz8; spf=pass (google.com: domain of linux-kernel+bounces-15975-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15975-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d6-20020a170902654600b001d3304a49cfsi21641946pln.496.2024.01.03.12.23.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 12:23:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-15975-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=FvoiyVz8; spf=pass (google.com: domain of linux-kernel+bounces-15975-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15975-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 84A9C285E12 for ; Wed, 3 Jan 2024 20:23:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EC6921EA85; Wed, 3 Jan 2024 20:22:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="FvoiyVz8" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C3E2D1D544 for ; Wed, 3 Jan 2024 20:22:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1d3ef33e68dso6104365ad.1 for ; Wed, 03 Jan 2024 12:22:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1704313326; x=1704918126; darn=vger.kernel.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=FvoiyVz8QnxDL5wEGzQ3TCOKVI9NfYSTikBJGbzZmBwfKlR3gI6A39PqTm0JX9wGjZ M+X7YUXZBjN7XH0xdTvfNJJpRnHauLCSlsZ0z/RFWRshinvQ6CTD0Fw3IIxNWFdedomM cdg9QUVo+tkA9H618VV/1t8zA1dowPiSay+HRmzF8Svxp0YNEK8Tkk9kH3ZNL/HAe8Hm Yp6wFznUv1hPEDkqzmuhDwnE/vNORsJNU0r6AT1HYiDYrTUkFgptCvVZHKZ7L+ejqhNX 8YqxiJTvTXtlxpVBVSWGtYXTeZJgygwkTWo968opX5baKExExtJnxCj86nPi2ZDpN1rd j/mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704313326; x=1704918126; 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=IZ8XwrleDN0r81+T9e4UnDiw8zrb2naROT/dD+2eoxkhsLfpAQVRrCS0QQnk5rQoez BbfBWzqsa7ZDvnCZghDue3RJ8qyKwX3fbUCsLUDjtB1mfHyb33v8EXTZjpdSXLFQfw55 U8IH1cxTXrL23s0n1lqZQPnjMxTVtMfsUwktF9W4uN42NVCyuvqoVI8lYheGXs/9eH0h DWYMO1oHaa8ezXgEYGb325C8eJ7vLzYotV3t/54gBlc/kz1lgIQ/w6oOocIdybscL3Uh xZHAqtyMemwfhimKs+YhDrnJVRHhfccavHMebPmD3Sz/BluoY+YufzLTAI4qfwxaTeq+ btIg== X-Gm-Message-State: AOJu0YxrYr11zkC7CwQPyseu7WrQTSAWfdmNQqkjNGZoVExfkuLFtZHb 0+0oNJq/ma0nrdBL1s+AtsNNhY9ONjMDxA== X-Received: by 2002:a17:902:748c:b0:1d3:edd9:1f13 with SMTP id h12-20020a170902748c00b001d3edd91f13mr1728858pll.67.1704313326148; Wed, 03 Jan 2024 12:22:06 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d13-20020a170903230d00b001d3fa5acf71sm24278739plh.12.2024.01.03.12.22.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 12:22:05 -0800 (PST) From: Charlie Jenkins Date: Wed, 03 Jan 2024 12:22:02 -0800 Subject: [PATCH v2 3/4] riscv: Fix relocation_hashtable size Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-module_loading_fix-v2-3-292b160552c9@rivosinc.com> References: <20240103-module_loading_fix-v2-0-292b160552c9@rivosinc.com> In-Reply-To: <20240103-module_loading_fix-v2-0-292b160552c9@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=1704313322; l=1020; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=js9HmT4o7o8yl7lcSP3vcOE6sOgYhIQV9xZrhoMilzw=; b=SCb2uRI3tDQm0ffD82YNnM5V07YHtzrz/w1KT4oUaF3KND9VKC87pPJdypEGMgzkkPQF9fFHn 3U5g8/i3hp1DCZbGzDsWDLQbXyWpmz3T+J+fT5KLQK7xulsUwWWSBLe X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787102134589713647 X-GMAIL-MSGID: 1787102134589713647 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; From patchwork Wed Jan 3 20:22:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 184843 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5245243dyb; Wed, 3 Jan 2024 12:25:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IEE7qVK7reJ0kNexc+mR5+E1iAs7+l35TJR8OET2wDWmManj8pMVIev1XsxACP1dhTbB6qK X-Received: by 2002:a17:902:cec4:b0:1d4:1c46:a9b3 with SMTP id d4-20020a170902cec400b001d41c46a9b3mr22392673plg.43.1704313541781; Wed, 03 Jan 2024 12:25:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704313541; cv=none; d=google.com; s=arc-20160816; b=auUq5YLQlHQkd6GQRfQ+i2GYRB3N1MRBG8XugqcBGm7nTvYuoZPX2adjctMjPhXKJ0 G6ljoi/wmUxKtOCp3bZrUGIs7M6PfFBw0PMIXrra9xRt/ZWAU85Cf3ORVTMDSvUoROjl Nbk+v/WNrrfYJExm1IInMYsWwZCrGPhRDgU1911tR463+NrvWvpe8tSJyCgBq3x9dNgm sZnq5W6/0ygmsU9Zw/g0sGQnZVsiV5n4VrDyRvOQ/oqEs3Fwa5+8lYl5EwdFp0OfNzYo Ot/uEMiXPB3TkFjz9V5irgky9HeQY1JXlpgVfJ4OTRHX7Xtnxi2LfbmL1GczPIUgOxOC 52Yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=EcPZp/8DlGxkljJ2IULxF796JgdWAzcJATDANUPFHbg=; fh=H/drdIrMKvODeMr3+XhctDPFSvTsTG2o8Mzihq3lpCA=; b=Sw922J+RvU/HVqD7XYYVBprK+oEOh/G5RWOH3PbD+lyh5d4q9xqlr2Wh/4nc/Us0RQ K3L+VPVzrJbpeZwPl2LiQaR99MALj4DjRARead9hj5M5YhW9/91j+fo8nJkUK7B8sNOm fwn4RGNj9ED9BF1ePJIozj2yv932JkqJstIPGEo1Nifz//D210MwZCm4b+TOi6OmGPCb PzEVPR/BTcTo5rtxy+g/EVPSOFq6nSywK25GRWr/ZkaV8sNyA8JXxbSKezN/3D9kO4zW dsgJLCsMjI6eoK/1PkinfNYrlNyN/62WCQ/GO1IDrJaOOYlIAz1JkaxUFpbKYgtG7d4X 3TSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=So4npkJ4; spf=pass (google.com: domain of linux-kernel+bounces-15976-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15976-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id l4-20020a170902f68400b001d44769173fsi17855615plg.245.2024.01.03.12.25.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 12:25:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-15976-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=So4npkJ4; spf=pass (google.com: domain of linux-kernel+bounces-15976-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15976-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 7CB9CB24D98 for ; Wed, 3 Jan 2024 20:23:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F09E01EB37; Wed, 3 Jan 2024 20:22:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="So4npkJ4" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE30F1D6A5 for ; Wed, 3 Jan 2024 20:22:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1d45f182fa2so56410265ad.3 for ; Wed, 03 Jan 2024 12:22:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1704313327; x=1704918127; darn=vger.kernel.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=EcPZp/8DlGxkljJ2IULxF796JgdWAzcJATDANUPFHbg=; b=So4npkJ41GmU4sK6gZvgfKT6DgrLFhP1EmmXbRBj9NV0kRWFVAFpcgqgcqgHSQQCIo LZIDiUlzKJgyq0B6GI1ihtSGHJduvk7s/3tyELsbVoU9WizlNOoAVMwdwqQDW6B94pP9 U8pI/793ONLMWAIljC8/nNm3hYGfJCjTNprhX2+LME//f0443SKOaPN/Q3nZERhwqJmE xGAvcrnwD4hCRm8RSAieFfn92rORHMZK8KCJRiCaF1X1f4vTSbUqvn6KNW98938qDzuR NyuWLeZxCLxQhLa+qP8yV9spDwKxPE4tVFTJpUHOqOUwTYcRdtItG9nt4CZd2BJ3FMu4 Qghw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704313327; x=1704918127; 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=EcPZp/8DlGxkljJ2IULxF796JgdWAzcJATDANUPFHbg=; b=kxKIh2D5qUEKKMbnED6X/T2+/ptbh2y8HBM1aIGzUchpRXOyPnQeqbHlpdCPWx3c9u fM6QeC9wx5B6rkLSYglMu1UWvfCK5mcJctdgMikCZFnLhmKJQiiCSkCGIhyVjKWxAAqr ElyMic5cK1boAICzDsxD1aN+TJtzWrZcF2eNWTBL7DdtquM7wLYMXyFyJjMlfCtEMcVY Yq9/mOjwmRzUAy0YjrDw06oXP+OKT6qYE4mVgUo98CsM+ppi3eij4HiwxlxyQIJ7NGTh AVinae0cf9Pt2qmgOByHoC9hdw6OWB98+ht5raCCVktCH8Dtgi93KHRnOhbvJCXlGP0L r7hw== X-Gm-Message-State: AOJu0Yw9QkOA7Y0kCD7zcfhXGFkWk/ShtHJKwT+9AQJ9oXHN4+9cfc63 mbsO+VmEvatUb4g0WqS+W3JfkZchtHDz3w== X-Received: by 2002:a17:903:98b:b0:1d4:d0e8:f9d2 with SMTP id mb11-20020a170903098b00b001d4d0e8f9d2mr1463670plb.93.1704313327127; Wed, 03 Jan 2024 12:22:07 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d13-20020a170903230d00b001d3fa5acf71sm24278739plh.12.2024.01.03.12.22.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 12:22:06 -0800 (PST) From: Charlie Jenkins Date: Wed, 03 Jan 2024 12:22:03 -0800 Subject: [PATCH v2 4/4] riscv: Convert relocation iterator to do-while Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-module_loading_fix-v2-4-292b160552c9@rivosinc.com> References: <20240103-module_loading_fix-v2-0-292b160552c9@rivosinc.com> In-Reply-To: <20240103-module_loading_fix-v2-0-292b160552c9@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 X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1704313322; l=2036; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=/ulcCnMFIkQarQGjz3X7NHIbZYgPXF/TzHke91JiC70=; b=2fwTTwWMrRHS1yLamkUKZvd9RFwXcDTwRTA8f+jCiAzGbZeyRz8gSU1eE+TKXv6+1XNA9u1WE i2oJi82DcH9AhH3z6euJBaUPy3PMy9P/+ZV8YT9MxUbCORDtooywt6E X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787102276314426130 X-GMAIL-MSGID: 1787102276314426130 Use a do-while loop to iterate through relocation entries to prevent curr_type from being marked as uninitialized. 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/202312130859.wnkuzVWY-lkp@intel.com/ --- arch/riscv/kernel/module.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c index ceb0adb38715..581e425686ab 100644 --- a/arch/riscv/kernel/module.c +++ b/arch/riscv/kernel/module.c @@ -633,15 +633,31 @@ process_accumulated_relocations(struct module *me, bucket_iter->bucket, node) { buffer = 0; location = rel_head_iter->location; - list_for_each_entry_safe(rel_entry_iter, - rel_entry_iter_tmp, - rel_head_iter->rel_entry, - head) { + rel_entry_iter = + list_first_entry(rel_head_iter->rel_entry, + typeof(*rel_entry_iter), head); + rel_entry_iter_tmp = + list_next_entry(rel_entry_iter, head); + + /* + * Iterate through all relocation entries that share + * this location. This uses a do-while loop instead of + * list_for_each_entry_safe since it is known that there + * is at least one entry and curr_type needs to be the + * value of the last entry when the loop exits. + */ + do { curr_type = rel_entry_iter->type; reloc_handlers[curr_type].reloc_handler( me, &buffer, rel_entry_iter->value); kfree(rel_entry_iter); - } + + rel_entry_iter = rel_entry_iter_tmp; + rel_entry_iter_tmp = list_next_entry(rel_entry_iter_tmp, head); + } while (!list_entry_is_head(rel_entry_iter, + rel_head_iter->rel_entry, + head)); + reloc_handlers[curr_type].accumulate_handler( me, location, buffer); kfree(rel_head_iter);