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: 185136 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5828651dyb; Thu, 4 Jan 2024 11:44:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IFo7IMQ0HgWxRayHaRF/JTRERxbTwnc/rss8oSXX4RGeGIR8OhMa50iEG2Tixdf2bjVhl+P X-Received: by 2002:a17:902:7804:b0:1d4:4a30:1a82 with SMTP id p4-20020a170902780400b001d44a301a82mr1057664pll.96.1704397463281; Thu, 04 Jan 2024 11:44:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704397463; cv=none; d=google.com; s=arc-20160816; b=GEYsPEXUArmwnBAwk9P8ijMmt++t+HIjc3au9Qx/Lp2lu73WvXpPM0rl6NbYCpm6rc eOyZkBxd9YePaV8oNkn7KfuBw2b2J3fmHX3kM2tFT5GiO2HkVJaKfkzVKn6whR4W31Aw nC/DcCLyYnAjbGI0wrcxsPytcmd6n2j2lmjmlHl8xKHY7Yn1koD4L2p7xrLl+vRPX1fG r4DrcILJHQQQv97+EDbIIyNH5Nj8MeatAfP6HGCTHAPnVQbwm2lerkaYsHKpTpjwPFvP 9xvawNh+SZBGgJPPuGR3BlsOSMXYqH3zn4mJDi+px2iROGk+TXYFrY/VoLMTRmxQ5+Ch IBPw== 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=Ny9kfRov8+P75JmnGTHpoKbuzA8kaEErhut+mKDGXUROu+s2OkJZFMBmPgizG8c/Ts LvG3pmGjKwuhF1j70CaGEqKMzVMX3MiX5MsZWto0v2kExTDLfd+BioTO83BsApNWuxmm OWbzfTG+PU+mV6Mv9Rp/TueoeXsXs/RzoG2p50QOQ7E5gN3pPdR4KFEupLvsptZU9AP7 Z9Z4N1Pr7Smm0UlycirHaYLmr/dz/9gEm5gudWRfbtADP+8mHNplFE0MmbC07/COGmmU TZkdle/6X3uL0CxZ4T2rTCVkK/I7oI4QChFFqRqLg3weWIgBJXpxaK58xrZ7myjKQAEp Evyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=scGTid8T; spf=pass (google.com: domain of linux-kernel+bounces-17177-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17177-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id n14-20020a170903110e00b001d473729a69si15497010plh.511.2024.01.04.11.44.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 11:44:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17177-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=scGTid8T; spf=pass (google.com: domain of linux-kernel+bounces-17177-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17177-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 227B2B24448 for ; Thu, 4 Jan 2024 19:44:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A3F542CCB8; Thu, 4 Jan 2024 19:43:01 +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="scGTid8T" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-il1-f177.google.com (mail-il1-f177.google.com [209.85.166.177]) (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 126132C694 for ; Thu, 4 Jan 2024 19:42:56 +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-il1-f177.google.com with SMTP id e9e14a558f8ab-35fff22678eso2957615ab.3 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=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=scGTid8TC9aU85cSvQWjhr6iMX92QpCxJd5CcTAEise3S4nqV7VS3tV1S8XsEC5LHf 9Ykh9FF3W3gD4HQA+1mFenYHP8ttY8i70H8IJEUIxubTCq5F1HN+yx2u7PP15ziLiG3N DCqfO1aB4uEU8tTZTBRcXKRBNSvqQkjfA2bfiXoW10vMpLlzL73Hny8YjBgWS4z2ABs1 5IfUU34xU8UAtkQLuQqiUe/MHnznUiY4JDPd6jkoDx4Edkl3M2m5PoS8v+SQpzSC0EkM ymmNFblI7ZH8gvvquStOyiYr6HH1rIFposkHIq8jlwjXWZC8shPNpmjNraRfpTa/YN2N w1Lw== 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=vdjlQ9fjv8+iZ4I6miOxo9xKFL4PRSq1bNLF0MGYXss+lDgS/12/+5RBuHjxhdmzVW QGoQy+sfJDo86mD/1JveGgs+OXffD9SmGj5cwpasMbszGpY2ZmTNHKguP5MIWgMQoZ6N 0h7y3G+FVxWQMQ+cGPUV9xsoqfRwzXMulYWVDfShs2V8SVmdMuviY0GzdmFAYrqWdO8I VYrqO+BngDV9ODZINOTh0T/RtxaqPt3gPMGl9KLY4tUudadrkTBfTBMzUoBzJhWGadjx s79LJUbDjnH2/P6cAj13AMM+2irVR+euZifzZ4xfzhZTAEMuCqLPoUp2lXEJLKrx7LR3 dYiA== X-Gm-Message-State: AOJu0YyN08mo4v+ZS+O8SiNKp0oOodIYaGfm4Uur+GQeDzNcgHTVWibH s7qAAU9+Ihl6VMJy/oUNNZRMIDjPTTn9Uw== 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787190274545459220 X-GMAIL-MSGID: 1787190274545459220 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: 185135 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5828615dyb; Thu, 4 Jan 2024 11:44:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IEtDjM4nV6yFHizFUenchvJVEVRpnKVlFjI/otRMQJ8de13aDkZfKfBJZA2YPEo0DMPtXek X-Received: by 2002:a05:6358:2799:b0:175:55b1:d00a with SMTP id l25-20020a056358279900b0017555b1d00amr879805rwb.13.1704397459078; Thu, 04 Jan 2024 11:44:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704397459; cv=none; d=google.com; s=arc-20160816; b=0FNxPIS5AmDwArob72VolEynxsVkn4RQQMAvvIiEgWVciA7r7m/2WQS6j3NgiTFR9g 11Dy74WvCaz1Ilm3ccuASJ3GhZ8awtmwvaM7rPx+cl4zrEqLi+Ng54cFSQuiLDeN0gNT +Kbrxf6wNqVAYbDXHcI4LVE0YPCrtsrRrphAzMsj2D22VoKmF24v2fLBTjccpL+g/gDy Js3ZxK84wXq268NVRC7BoS33v9fn2AM+RlMtUZIGYMy6IMeblZlDkxyowlDxNSrfbCLy RdmGfqe167k+DZqAQOO9CGRoWVu/hg71uhFHIbGB3Oq8Lr7eXScVQ/RiUw1gLfvqsIJS DKMg== 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=J5Dr/iOmrrwZkQH0ghv8VQRQwSF7XdgT3dvLHYcilBPuQHc1stLrhmbcuxXzTBEk3+ suAxsyKsKdtkr3OR9YvJ5zHYXcC0mqZy0OgGhL4OKSWpw1sWuLpUti7b9PmRHvUFqdqM Vbr2GZai5KpE3p3OMV0XF2j5wVd9snJ+e6oLXmC14gfuNIuITMHm8vp4El1w7B6Gd9KO eboU9NFuaNNxeIPQ7qWofjrEgcXK5F2/Og1DCGXElL7thb4RxkD7o7crqBi37lLC1RKT 06H1D7SW6alRcF937HtqPmZ1lvIM4xwiEyBJ8CJfkOj9sCyii3FfyekPHltr8IC3U9lN Evmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=ippr5imp; spf=pass (google.com: domain of linux-kernel+bounces-17178-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17178-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id o12-20020a05622a044c00b004283795acbbsi186577qtx.527.2024.01.04.11.44.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 11:44:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17178-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=ippr5imp; spf=pass (google.com: domain of linux-kernel+bounces-17178-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17178-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id D6C4F1C22522 for ; Thu, 4 Jan 2024 19:44:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BD9412D03B; Thu, 4 Jan 2024 19:43:02 +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="ippr5imp" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-io1-f54.google.com (mail-io1-f54.google.com [209.85.166.54]) (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 7456B2C6A7 for ; Thu, 4 Jan 2024 19:42:58 +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-io1-f54.google.com with SMTP id ca18e2360f4ac-7ba8c218fe1so42871539f.3 for ; Thu, 04 Jan 2024 11:42:58 -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=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=ippr5impszhAyE88Isolx5kJ8Q3DYU3doweVByoLpHLaDLCFxasHH3aLGCZLMIjmkR xf9DAi3ztehOn2gSSrY1DMM5tUTjqN1+xpYzKcZf4ZF3dw5Zo2+3suKkhS+yxXOUy0Ve IW8yQYvfoXVvH3PRuN7QSAk1k9v0xcLMH0JQHKOozLY8Jwz7ACgQjBzTDuUXfMZqyRHX hQ2aea19lU0d+2vrJTktujzb3OpbL9S/PiOxSkQhPxGiMBrn2ATyKLsesv5mRs4WfRME AaBTOhRCMoI3qtZLJRJrJZUSyWcaBboH4HPXdygku8UimrmIObpRfzndKV7FcW2SrmGF ykQQ== 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=hd4shSdHAHxFGja8Gq1JX4wG3Duaus+RUgLau/g96M95yShOSGtb9dlPJKQLXDqhG4 kDz3WLguLNrBQMcClilT0vrZB124S9eP33WGtk/jOYCg7N+I7yIXCkkpJ9KKOwCRrH9f B6hoPF79UUaA/RN44Ulr97kIA2epGDSN1/l0UFmBtn0o/89cv4zwWvYOJViZzvnWbnSZ NPTNup/8R5Yjdw0xeS3oUqCrimepZu9Kcl1USaZf48aX4ioSCjJvmPOi3tzexXgoUMbP yy2bHgR/YcfLguyvsK2orBMGNEvV8nAE8M2sm94N96zdLmNEvi0dvQLPYITbceImPet9 urtQ== X-Gm-Message-State: AOJu0YzrokgOhs7mVLNT/6QFSM/pOpdWNJDo4lIrIMrtgRyJ0TyFrgkU WZ1qjJFl+8wZpZbhb7VuZjM7bjrPW6tTGA== 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787190270165348313 X-GMAIL-MSGID: 1787190270165348313 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: 185137 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5829461dyb; Thu, 4 Jan 2024 11:45:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IH7RquO5d+K2TeHMVSYYCFkQ53Rul0iaOib4WqBxbrILeqmP6pqFsNVAezYR74wbbfc21oP X-Received: by 2002:a17:902:70c2:b0:1d4:c313:8081 with SMTP id l2-20020a17090270c200b001d4c3138081mr929042plt.129.1704397527241; Thu, 04 Jan 2024 11:45:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704397527; cv=none; d=google.com; s=arc-20160816; b=kn+cuW/Nm97yxL2skZbveqiMsCmUSoeSMCfwgTUYcnb4Ryyxl8BusmxSKY4GQLvDmk wsajSqhkfucbtZ8TJt4WeXDNbb2t5qI+c79hQtIWXAddoWxbtEvvHLI9NMBUz9+WzKTJ HUdTQbL5QW28Tu+vIoGWmrCJkoM2mniZMqVGJq62B+gc5R9w1+i23hWWd+2H597gc9pS bfQTMAt7V+wjWUW2DgC9YcGJ6BsZ7DgxTqS52C7S9yiXKODXzApfTbQjTA18QDKp/syR Y2XdEUdhxZ/DVqSEqfPerbmKagAldhAFRGvWM9BgwlAou/4U2HETgSQhpu/j1IEAcjnY MIng== 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=sOkP9WDgOwe0B2X4VNov8jA3sINLTKs5UWsNzQokLGRfMUabuKS8pRrUGetOXj/CNq 259uxvhauS4GigrmCQt1gghiADctuP0HaAJ+wIjawa+1TEWbTG7Y4gf33g9BnKChIDiu fF9CSe5npdzTAWw8SDwYq5VekVohbztJpEXHoHJamxnGc+G5QNXCIYdt67Re1+ITcOFs rWc1K0uzAJE5OXtAFEn/lCUoUbbCytbFBEBp/PyJU4yOvK2MuBXS7kPGlLhkC2xdsCsk L3M3JHwoFZdjyc4l2Vd3Yb+DYpElL32+2LxR1Zt9ZapcI1tHt62RkJ1wDSIJ11kWBMYc YTaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=t31Jxc6I; spf=pass (google.com: domain of linux-kernel+bounces-17179-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17179-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id z13-20020a170903018d00b001d0b6ba6109si22788645plg.248.2024.01.04.11.45.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 11:45:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17179-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=t31Jxc6I; spf=pass (google.com: domain of linux-kernel+bounces-17179-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17179-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 50B9AB21EE7 for ; Thu, 4 Jan 2024 19:44:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 82C972D600; Thu, 4 Jan 2024 19:43:03 +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="t31Jxc6I" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-il1-f171.google.com (mail-il1-f171.google.com [209.85.166.171]) (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 6C83C2C6B9 for ; Thu, 4 Jan 2024 19:42:59 +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-il1-f171.google.com with SMTP id e9e14a558f8ab-3606ad581a5so2041095ab.1 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=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=t31Jxc6IjDIDFuriAo29YKsXR8UshY8Ea20epAztUpL50/EIjoJhRdxFl+qaGaSJ94 xFf5R0MWMeqIPpnCDJ64fFHmditFJbQuZ6vfkr622pixW1Y+12ogQUOEaD96+3pNw/A3 ydU8mjfqkLV8nRitzO9F8Kp/PwAAibZqcWvE1pGXONNCGVQgzBt09pKAqaukSOK/74Ri X6LiRteCMfwFrTEnT5ET7U+JIm+BeHu0AN3nesadEa3WaQgZc/V2DfKmKHJEC1caWiat SfMA6EqYoHQNe6J3MEEXUmDEZm20FgynEG41Cg0yqC78oa+J5Cegskyq9L/Kcxuvd8va EdEw== 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=Gh9hirlbTGkkh3Fa+P7kAEq/iqlpfkfZ2YF4JWROV328jF8IsaE1lA6+LfX+pccUj8 3nYUrUJkmvjWTLW9VKy9AiH0IDGPpchY79Q3QlGFcl7JiibJ8cY5FJFZ+JX+U9z1zdR9 cuNElL2iJEZf36D6NBnMXH/G/Pu2pjiutv9LpHGKAf7JVB/Y0V4r6UkoQ/fBuakhAnMH IhTiZh7MYDis8l1krp/zVwLWUVwdShr8syMLyCvDLOkvbW4TnDcHviXAvjhqRAAFafTh btAKivjmfxTrjfy/8eaWRLqYXURb7rsOdRn+Y4ldiKjtB/FP2f9AvK+VuuEf0a2b/SNU aYjg== X-Gm-Message-State: AOJu0YzVIi6I2th5O5ZI1YIvvoYzwdg9JGvgJPX6JBS+QWSdHphTEZsn RpcYPS2LTsLOxwSsuUJJ8XDMXzm/apFCtA== 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787190341767524534 X-GMAIL-MSGID: 1787190341767524534 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;