Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp1314796lqg; Sun, 3 Mar 2024 04:57:52 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVc/Y4vP9xd9rpTOgwxsqOAf2y0qj+AjUxwFAbkXW+3gUrnOHSBvAmo3rTeO8O7wmLs25ppzqk9oxvH8zzy4IDM8hjm7m3kO92h8fAqMg== X-Google-Smtp-Source: AGHT+IEyQjC2zWACbeHL6wkKT+qH9gKT+Vv2R2qYGX+/geJRweKz2O8ujrscRVj2JabD7otnqlOz X-Received: by 2002:a05:6512:401b:b0:513:46b4:4eb4 with SMTP id br27-20020a056512401b00b0051346b44eb4mr443118lfb.3.1709470672576; Sun, 03 Mar 2024 04:57:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709470672; cv=pass; d=google.com; s=arc-20160816; b=hn7Fl9CD1o8iGJqMUdgsMSlP2RoojYW/TwfJZeVwwiyuxAkhOnLrAH15FeOusw24gh UKFfL6RxbnEhJATE5BXgx5QnaNh8v6QA4AmT1kcojZ02rJY6mRhcsLA+6uu7X2HcM8D9 KaiS//Hff2BWFuUZIddxj2oQTQo7sbhM9OgrPTI+QcfTwXA74az3GUvAuKeVTBZyZ9Bx YDL3sBeLysPaTWmdoeIusnRdoBVjyWaPDApJhOK6OpSQwG3Q3hF1xX/lHDFZToJZwYOh MgePj6d6EJsWKYyZ9yIyZx8JUFZAr1H0sIKL00h/T0xRKhQEuSZphUQvLK/mE+CYq95k 7KRQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=APJ38DBI4uESRZ79q8aDyPlfcV5+7jWXse+v+R60j5s=; fh=GB3dU5Lnnv/6v/mpZNoQV0u9F8aubc/2GQdTVAtEnoU=; b=IpetB2jxN4cTJm8ubS034iQWSHeOO0CgsDpvwWHpSfftqMwZIOvJgYvL/CopX8gJdN Mgf4odINN7YuwQWPN8RordE8DKMD0e7gk4Rc5I2LUkimAZ20HRqQ+Pvqsn18RjQIaQFP icZjwAEibw/MGA0yqlaNHhcTC6o5mA0qtVnme4d6UDe7+nFfIM2sfeKhJQxo3eCZc2GQ LHVEI1eniKS1tve2jtgXYk/JnWwxkuT+5Pat3CuWLEhh9WBG5KnEBKas9rX9GqUSQeHx khMGkz9D8hPMd4IF1rfmZEfAg30mjCwo/Y39BcYUImKKQDGX2evUWIY3FuKg6nPrmEdY ncJQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lMXJ7i86; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-89738-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89738-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id wu14-20020a170906eece00b00a43093c3e33si3240004ejb.995.2024.03.03.04.57.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 04:57:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-89738-linux.lists.archive=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=@kernel.org header.s=k20201202 header.b=lMXJ7i86; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-89738-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89738-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 4946A1F213F1 for ; Sun, 3 Mar 2024 12:57:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A6105C8CE; Sun, 3 Mar 2024 12:57:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lMXJ7i86" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCC4928E7; Sun, 3 Mar 2024 12:57:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709470662; cv=none; b=iLBtp7RMjpqghrAk3krp2cq2Heouf76oBSkOTXhic8ewToxHfWBtvhp5gVa4zEYs5vQdq+5MLLmEAnwijqedKhWH/srOpksuWvGwwFvZ5sJwPj5Ccb2WMAAkp2p5Ik0m3dM5OW3DKqL3HAlRb4sF3nfxfID/gGBFWj00D+sdTR8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709470662; c=relaxed/simple; bh=4ch5aMF3KIky3EvroYwtOum5t1jE63gLQZEJ509AYzY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=daHiCzEileCc0MEA5lsxyAP9LYtzC9Lvud2pgVLnvlNVF4JfOBe7xNH1uqb4DkznXOAyTkZPQ19H8vbKqUz8DMur4LSqpdoppnKapXrhCKXE1UQFwoFUi+C9NhmKfmTT+LCwXH/AhHx2EtDy5G0K8kfAOvwoEQYlOQNPCJk96uk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lMXJ7i86; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8A27C433C7; Sun, 3 Mar 2024 12:57:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709470662; bh=4ch5aMF3KIky3EvroYwtOum5t1jE63gLQZEJ509AYzY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lMXJ7i86uTVPjCDa/06YKBiPyBc+9L0b2PktC0RdAo1btyVBO7MHBEQzlxSPKALNc OIT+9gcE//pT/oH2FTm2l42YUA+J2/t4L6v0XhnBWeJIpKB0mp47bcv1+SuE7PWP+/ 3PPDBqyrZQiIbA/c83B33EAHdJUzQ7MWoIrh8QADscA3+VpyV84ojV2xYTEq4mGn0b cMhEdOiih1QScHPg/TOXuxK60EYbhJRVO0s7/k4pKNlWhmvRBJqxskrnQtnd3YDzGs gzIfOtBiAHSsLLmNneEuvEkKuFBF+MBf3sA/yALf3mCXn4jlMSG/eSqRV861dtyTp7 PqsF+LDKcsAkg== Date: Sun, 3 Mar 2024 14:57:37 +0200 From: Leon Romanovsky To: Wenchao Hao Cc: Jason Gunthorpe , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] RDMA/restrack: Fix potential invalid address access Message-ID: <20240303125737.GB112581@unreal> References: <20240301095514.3598280-1-haowenchao2@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240301095514.3598280-1-haowenchao2@huawei.com> On Fri, Mar 01, 2024 at 05:55:15PM +0800, Wenchao Hao wrote: > struct rdma_restrack_entry's kern_name was set to KBUILD_MODNAME > in ib_create_cq(), while if the module exited but forgot del this > rdma_restrack_entry, it would cause a invalid address access in > rdma_restrack_clean() when print the owner of this rdma_restrack_entry. How is it possible to exit owner module without cleaning the resources? Thanks > > Fix this issue by using kstrdup() to set rdma_restrack_entry's > kern_name. > > Signed-off-by: Wenchao Hao > --- > drivers/infiniband/core/restrack.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/infiniband/core/restrack.c b/drivers/infiniband/core/restrack.c > index 01a499a8b88d..6605011c4edc 100644 > --- a/drivers/infiniband/core/restrack.c > +++ b/drivers/infiniband/core/restrack.c > @@ -177,7 +177,8 @@ static void rdma_restrack_attach_task(struct rdma_restrack_entry *res, > void rdma_restrack_set_name(struct rdma_restrack_entry *res, const char *caller) > { > if (caller) { > - res->kern_name = caller; > + kfree(res->kern_name); > + res->kern_name = kstrdup(caller, GFP_KERNEL); > return; > } > > @@ -195,7 +196,7 @@ void rdma_restrack_parent_name(struct rdma_restrack_entry *dst, > const struct rdma_restrack_entry *parent) > { > if (rdma_is_kernel_res(parent)) > - dst->kern_name = parent->kern_name; > + dst->kern_name = kstrdup(parent->kern_name, GFP_KERNEL); > else > rdma_restrack_attach_task(dst, parent->task); > } > @@ -306,6 +307,7 @@ static void restrack_release(struct kref *kref) > put_task_struct(res->task); > res->task = NULL; > } > + kfree(res->kern_name); > complete(&res->comp); > } > > -- > 2.32.0 >