Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp1604583lqg; Sun, 3 Mar 2024 19:21:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWEyiiGl9IzUlYyCu+S6Z7gNrKgdMVd0GBWf+UrGVdUyGcyWWGNjealA53eZp6/vUV8wIOEN5t6i6JuP5ZkkCLQkf0g91J3+BpTLviqiw== X-Google-Smtp-Source: AGHT+IE2LKICSRuaQ2T4Cw2Wdq41/87XOWSxScHA6BLpHPcgxOcvW1XOcvWKBTmfE1j/s4exWc9T X-Received: by 2002:ac8:5955:0:b0:42e:dcf1:355a with SMTP id 21-20020ac85955000000b0042edcf1355amr7587226qtz.32.1709522511177; Sun, 03 Mar 2024 19:21:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709522511; cv=pass; d=google.com; s=arc-20160816; b=u3xTzEMw9arGndw1W1VWyx3byt0Jbe3mYjxHvgW3U7LR5y1aHWIMlCh/I9a+4bhQXf ngq2/+7Zg+3SmFDJn9bI4g1BvkGPG4c4vizjr5gPVaoncwfhQzePeXyuvJY/tWCbTQix bZx3VgdZbkhKx0Q95aW6zaM0Y5fR756HtiUQWSLF9vc9Jkgwg4RNSc1xc/gFJvjMJWm3 E7QgLsUL+kKMIuYH8k5VAhnefNszbDtzlGBiMeOFanV/cCTOtTIMV4xn5a/Je4MMzZBI ije5nrbQAka7at7E5tNx6iedh0Fh7Xlhd7h+EhhH8r9dhyepS9nrmXXJhAJPR/ffhbG5 VC5Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=P7lKYlHVCg4lBXVSqFpghjklbksQaRYsQ8LO4ufvrec=; fh=Zf19Wf16qe3DaZp7ziUgtf4gjvn4LSGfkRSvlLaND+Q=; b=vipBiM8QwOwwIUfNNcqAxtZa9NZy9mt5zmbJ5lcpGxXXfHKmccaddMAysTDFFvA9ZW WQOj8uMpoYgv6MorQmQ28PIqf1j+zX6ox86wQ6aho7ObrrdsZD2El/fVkiLycmXVtyEN MtaxapdMm220ahJfiich0/EAU7gTEv+i4e+zTVjNcHM+1RQ5dqMl23kmJh4FWx8z35ym otUJ8HBmSHP2SzF9mQ4cyiUndDuWxfaYO+3YbbddkGlUOigglCXfvzwGVZ3ueqO84T5L 1HjGy+FT3BwccCB55pVkZd+tDeFN5hn6DMLFR1ecVdkuBwqDXs5yJLXUXEnEsKBrf8wO Ad/A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-90007-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90007-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id fv9-20020a05622a4a0900b0042ef7077bc1si85648qtb.550.2024.03.03.19.21.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 19:21:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90007-linux.lists.archive=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; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-90007-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90007-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com 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 E59571C20B30 for ; Mon, 4 Mar 2024 03:21:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 14F794A3C; Mon, 4 Mar 2024 03:21:44 +0000 (UTC) Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (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 BD1284688; Mon, 4 Mar 2024 03:21:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709522503; cv=none; b=WJsU1/g0QDXprEguzgCWFsOlkSoJvYe71y3ZLTXPh7SaphKfVePYHjBW3V2I2lIF4AJy45t0btCLfMVVnibh/tucjYqSaec7wjGptp8TdZmLzJKdsNL7ke7KUYQSdV7JYhEwJYmFo0pmIkipGzzV830V2oH1M+y9BWelFdmzt6s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709522503; c=relaxed/simple; bh=N2l4Fs5hXrcVqwfcD1WSV5rE9juV2u+G8MIDGqfCf3g=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=qJwMyhmPRK2zLfU5HJoWry/R0HhfKYIKmZtyTPPx1bPnLYpBNjIFr6gArrjcEh6G6InzT46ZegUUHgps8xnVPffTYowDcIxj52INz5uOMYBE+JEayYXeMffpDU4lNxJ2sxG4QswnK88nL7WIubKIkAU5pS9ExkQcnfssCfmHmVE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Tp3ph3G9fz1xq2D; Mon, 4 Mar 2024 11:19:56 +0800 (CST) Received: from kwepemm600012.china.huawei.com (unknown [7.193.23.74]) by mail.maildlp.com (Postfix) with ESMTPS id A24AE14037E; Mon, 4 Mar 2024 11:21:31 +0800 (CST) Received: from [10.174.178.220] (10.174.178.220) by kwepemm600012.china.huawei.com (7.193.23.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Mon, 4 Mar 2024 11:21:31 +0800 Message-ID: Date: Mon, 4 Mar 2024 11:21:19 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] RDMA/restrack: Fix potential invalid address access To: Leon Romanovsky CC: Jason Gunthorpe , , References: <20240301095514.3598280-1-haowenchao2@huawei.com> <20240303125737.GB112581@unreal> Content-Language: en-US From: Wenchao Hao In-Reply-To: <20240303125737.GB112581@unreal> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600012.china.huawei.com (7.193.23.74) On 2024/3/3 20:57, Leon Romanovsky wrote: > 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? > I meet this issue with one of our product who develop their owner kernel modules based on ib_core, and there are terrible logic with the exit code which cause resource leak. Of curse it's bug of module who did not clear resource when exit, but I think ib_core should avoid accessing memory of other modules directly to provides better stability. What's more, from the context of rdma_restrack_clean() when print "restack: %s %s object allocated by %s is not freed ...", it seems designed for the above scene where client has bug to alerts there are resource leak, so we should not panic on this log print. > 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 >>