From patchwork Mon Nov 6 23:34:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13447595 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A266C4167B for ; Mon, 6 Nov 2023 23:34:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2FF226B0258; Mon, 6 Nov 2023 18:34:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 288B36B025A; Mon, 6 Nov 2023 18:34:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 12A286B025B; Mon, 6 Nov 2023 18:34:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 007BD6B0258 for ; Mon, 6 Nov 2023 18:34:18 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C8E2B40964 for ; Mon, 6 Nov 2023 23:34:18 +0000 (UTC) X-FDA: 81429135396.29.67B3241 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf28.hostedemail.com (Postfix) with ESMTP id C210AC001A for ; Mon, 6 Nov 2023 23:34:16 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=l7EqwQOv; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf28.hostedemail.com: domain of sj@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1699313657; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=w0kEAmDIiB+nNiOxil7eazkNdbm+gUZoY9qzJclbFfs=; b=8G1a0eS7sa8ioIBJMerif9Aj5c0iY7sWHPAfjbGAEjfqcZHG77vz7CBHDTuOYnF13szjpi fjrC78H0sd1X3edavyWG9Kivm1IvXhjcT5/r9Rfr7h04T2N/+yXq/I8nD15vfDk5vqU3/q eGHMr0mZSzIm4vo2R3RVRuBIuymTzDM= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=l7EqwQOv; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf28.hostedemail.com: domain of sj@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699313657; a=rsa-sha256; cv=none; b=G+lRu7fSlKiyN3EAIRPCn0VpDdeaPSmPesYPEpGnhQYLnEo/nCsVYsudZzA9PdZqqhjllH TaCr7UDGeSVG8PWtXHJmEzG5Q0cksfPFOrd7mt3HvNeN9bgT7fMDJZQrQTtPg6RnOX3UUt P1Gox0UmD85dLQh5vPEtzdTdPhiGyRM= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 4F5C3CE0E3C; Mon, 6 Nov 2023 23:34:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B5E5C433C7; Mon, 6 Nov 2023 23:34:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699313652; bh=W1YiwkaUjwsrSNghKHLS4esY06g2LoID2WDuKt3I9RI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l7EqwQOv3ujXdIdXqqLv7Yl2LZRZP4XIrLtoom+8gJLK5oV+OiHLT+vhbC/H1l//N 3ys60zJfeXmo1OBsPoTrzHX39yAklgEWMZGpaL5dQ84d1Wm494msHCkhjxa3lLv/o+ bmlBz1f8LPIrbknFW1iBJdvA5QQacQ1blL3tn2CUS9dsVOdkdhD3h1h9hzWsXsD+lD cQcF6kLh9zlF7uEHKE33vL0PahvmSow2SGpG0LP18EhMlmxAFu7oZpV7nWkVBLUK+y KXwSQej944ZLmBtdEJft4FhJiRYzEA2O1R8i/uGHUKVQC5EUGKH8wVyaId3jKSixkj qTvuPBpthovEA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 2/3] mm/damon/sysfs-schemes: handle tried regions sysfs directory allocation failure Date: Mon, 6 Nov 2023 23:34:07 +0000 Message-Id: <20231106233408.51159-3-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231106233408.51159-1-sj@kernel.org> References: <20231106233408.51159-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: C210AC001A X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: ji338zwgegxntxxfnwhjc5ewy4jourgk X-HE-Tag: 1699313656-500313 X-HE-Meta: U2FsdGVkX1+vq/CmRHZwTwuFgfNtY4XBfFY+GzxseLYY/6Nz/gETnhxx96zUEDRsYSCnBltM0q7dvSBN3oHk/FKU3XmYljm4aGT8QaF5NoTAnJmg7tu85K8z+ERsBzqQLJRucDwgM1dXYnLo6OSKbOoubcRt0YL84ALfWxi5rlvvy+b/Fb4r7T2Jm7vJ/TbjzLSwCy0SNGI2b+uJHgTVunzEQ2HKIxI65WGSdHjGv/rRM/iBgZ5zDDHuCrsBtq4BYdh5BOoXbBvmmjipQhlqD96o1UdkYcscxtFKtCEu3CNJv56YT23gBSilT276Yl3WIzfoPCfW48Mg+DpeXh0bDwa0u7/ejQaKix0XVpI7St+M4oJF5Kn6qNhB8HcPkwXa3eoOArMMR6f8rXdcdR2uczyLVSsStC5McO+2J+Atz1m9AJFm30ZCCbpJJc1Bdwj9E/CTXvciG1mo4wi/i+VawCLHju76tHmevDdbQECoImv8kQsJ3jNP08Uz9BE57Yr5FsYHaHrr5b9brRgs3O/RbPxzM8JvdJyPntIqgyPFkkUhyJpGODSfjNg1WRcm3MVrm8OYP3SVeBjUTBms7KSKHwDXvH5QHuzZQZwk5CkVKqbwT0LokIdX0YX/Da7Vr9p92jYfZkhmBldm1mTRaU/g7RCX5pGlYluJJNYruKgRj1mZbcoDRoyR1PmCQtSoYlGF3DyID9TXFkl5v22tVQ3BJBjvUmKVKBoyqJHqQWvlctmJ5HLRhPw6X7BNeMvTTrTlsYsrwCwSW/gsqQPnbyvbiCweziWYRbV83a4jAjdY1sRBFuip6hehsWHPHRY7ump6mLfZkkr4zijxBPaT3mDbTslsqElVX5YZZhZiiekJfs9MlssD3YCxEHAxnlpTupIIO6yWtBRT/Q7ce84cpM3hKnPbgZiFl8qISDUJFkK+AFGqU97icJonu6xDLzXfQd8fuyfSeX1gHZ6pnB/unNw FBklTq83 SIWBdQaN5nK8gKqE2iIsoO44txJ4OOAMWZG9fHofNmAYLF/x37RLyt7UDM5GRx9Gpu3pudhYdTbQTkijLzFbu3NMHcFuwA85Xon6y5x2VEQ76i7j5b2wFtu6S2nTeFy7bTrKVht10ImBSh6kLwSBphgUwD0IOmAiOgXBdpAiUUWbYNqyCf0YHWwM9oJm2cn0L81oExqneAHHpcDPup4t+3iEHgdk/ZA/hFg5yXy0rf4A8ghxyVYTKAbvvqV1WERUEhWt9 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: DAMOS tried regions sysfs directory allocation function (damon_sysfs_scheme_regions_alloc()) is not handling the memory allocation failure. In the case, the code will dereference NULL pointer. Handle the failure to avoid such invalid access. Fixes: 9277d0367ba1 ("mm/damon/sysfs-schemes: implement scheme region directory") Cc: # 6.2.x Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 45bd0fd4a8b1..7413cb35c5a9 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -162,6 +162,9 @@ damon_sysfs_scheme_regions_alloc(void) struct damon_sysfs_scheme_regions *regions = kmalloc(sizeof(*regions), GFP_KERNEL); + if (!regions) + return NULL; + regions->kobj = (struct kobject){}; INIT_LIST_HEAD(®ions->regions_list); regions->nr_regions = 0;