From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-98.freemail.mail.aliyun.com (out30-98.freemail.mail.aliyun.com [115.124.30.98]) (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 0C41F8F58 for ; Thu, 2 Jan 2025 01:59:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.98 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735783193; cv=none; b=S53t43H1Q0xIrxktz/XS4rzj6hDoLnqsna9v0tm3Zwo0i3vVejs2OeMAIvnJtorzDZ4OQmlOQm6B7HPp4VSoC1e6lW0WNCjQ5Ohdz6Y1yg16dNNFuX68qILjJ6f4iYX/BfcNH2NO0GHxBZKEJ0g9Dw2GYvrx90+pnQNJrIG1Q9g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735783193; c=relaxed/simple; bh=ASjvLhUR/rBS1mLTCLqBRuYsshY/vBLNHmCnMWa7W0w=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=cIgmb5kpANG3tVfaeHXVZjoSBGOjSJSnlp0PJ5iY4Vm2rzbeSC3cNQ1P3vbk5kSpCwyQWyjMMX0QuGD7ic5nfVauVdwuyGA3xRZBR/+LbL5yOzquO0JRTTrjEuaOohWYMffgAYL5HOClCREvy4GZifeUs88geEq4FFquyo33y4s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=F4Ajq3AY; arc=none smtp.client-ip=115.124.30.98 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="F4Ajq3AY" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1735783180; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; bh=U4Myg/4xE4EfAJwbN1/V50Kbg6GoR8eCgZ9zLB6fyVA=; b=F4Ajq3AYLKkfZdUCxYAuUEfAAGfLtcKVHMjcQUHOrg2l3FEDuqpirEt6YVVfPIS9L2qaKUq8rWlgxPTlkPEMvan49dcJA4DYJL/AiAsjjW5ZlvCaH8ckKERAflm5HRIJZX0CX74xBEORdlbkTDb0gQr98IyXFnRNlyp6Ws5i388= Received: from DESKTOP-5N7EMDA(mailfrom:ying.huang@linux.alibaba.com fp:SMTPD_---0WMhjDK2_1735783169 cluster:ay36) by smtp.aliyun-inc.com; Thu, 02 Jan 2025 09:59:40 +0800 From: "Huang, Ying" To: kingdix10@qq.com Cc: akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, ilpo.jarvinen@linux.intel.com, bhelgaas@google.com, mika.westerberg@linux.intel.com, huang.ying.caritas@gmail.com, jhubbard@nvidia.com, peterz@infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] resource: use kstrdup_const to prevent wild pointer issues In-Reply-To: (kingdix's message of "Wed, 1 Jan 2025 21:49:08 +0800") References: Date: Thu, 02 Jan 2025 09:59:26 +0800 Message-ID: <87seq2dlhd.fsf@DESKTOP-5N7EMDA> User-Agent: Gnus/5.13 (Gnus v5.13) 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=ascii kingdix10@qq.com writes: > From: King Dix > > When a stack string variable is passed during the request resource > operation, it causes an oops problem when executing cat /proc/iomem. > > In the original code, in functions like __request_region_locked, the name > member of the resource structure was directly assigned the stack string > pointer without proper memory management. > > This fix changes the assignment of res->name to use kstrdup_const for > string copying, ensuring the correct storage and release of the string > and thus avoiding potential memory errors and oops issues. > > Signed-off-by: King Dix In general, I think that it's good to improve the resource requesting API. However, it's not good to use so many GFP_ATOMIC too. Why do you need to call resource requesting API with stack variable? If it's just some programming bugs, we should add more checks instead of hiding the bugs. For example, if we only allows kernel rodata and slab memory to be used in resource requesting. We can add a VM_WARN_ON() to check that. [snip] --- Best Regards, Huang, Ying