From patchwork Mon Nov 6 23:34:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 162229 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp2991845vqu; Mon, 6 Nov 2023 15:34:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IGKcgDlnSAqdzTn/niENkr1ObErn93ERIC/nGsPpW3Jz7jQ5aY2pC7P6d/Ua6qHoe7hH2Dn X-Received: by 2002:a17:903:22cd:b0:1cc:4fe8:c6c6 with SMTP id y13-20020a17090322cd00b001cc4fe8c6c6mr1433637plg.6.1699313659088; Mon, 06 Nov 2023 15:34:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699313659; cv=none; d=google.com; s=arc-20160816; b=P3SRm6jbgIWQFffQVDgLamQylBYEOyqfFUs5mMfHFMcKWRXLYcRVGa4B9AdYvEJNer DitsFZ5MBOAgI04twcruwHvqVZbw0RRSs9TkH/H4MapZQrGfaughwaxkcHBoKw0IB0P5 jmhRSxSTeZQ2jJad0NFHMMGPHHBYloRw48KgCffWGwzTIBaMKkeDKmeWlgAus9UquqTP UcH2i7/9Z4LwW+oHMd+IEWTk7oQ3xHE4L1a1f8dtsEj//0vdKNBHswJm/qZMqF1tVw8u NRUjjL4xL9RMogsRxMKVxciVTCIql5mMnFvw+3KQBmiLzWraFgscPXN4/I7l+GWJKqMI lSJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bjxQ1LmSyqWFZikG6cYNs/ewKsq9df3Hd0LideRpIcQ=; fh=WXAAPMfSxLmsB2WJ8A0s7FPd+eTotx5bYas/XF5lzN4=; b=VHlTJykluF9iyNWFIxOGpj6crvfav6Bd40kC6OrXne6rNm+jjkRHI63tnCAjZEmGr0 jfcy0mrBrXohuRHUeE06wstkhScqsQO8u+QigO7+9Rsm7BxjW6owQsOuNW58eoxJButL yMIKOeoYUmAaa6Yw2eKE219JRvzc7ORCgorb3O3rCO2LUxZBxnISjFnCGLAbQvyzfcTc rKg1rD0mr9OJgux/W5MdMXvFStMKg8H6NYD1q/k/Ns/erW5HplwE/SMpP5laPd35Fk9C hTsN8dXuvgOvfFLanDVorVpu8gMyUWu2efSB1MnVgL2KBl3vug4SZovNsf27R4r/wu9m ihQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UyoPvSX0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id h17-20020a170902f7d100b001b7ea20dbf2si8782205plw.224.2023.11.06.15.34.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 15:34:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UyoPvSX0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 3FED880FA863; Mon, 6 Nov 2023 15:34:18 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233390AbjKFXeP (ORCPT + 33 others); Mon, 6 Nov 2023 18:34:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233321AbjKFXeN (ORCPT ); Mon, 6 Nov 2023 18:34:13 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90F9883; Mon, 6 Nov 2023 15:34:11 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D15AEC433C8; Mon, 6 Nov 2023 23:34:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699313651; bh=MtIChiGlAMl9WTJvVSRQmuDT6RxSD+NBrsKsO1Hl6Io=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UyoPvSX0uc/PWJFKoa+VUDxKq/E/FXknGdVXc5LledMo3lXe9IT0oRt5RQemS8eDn ofZwHuP518ZGSpd/p2iBOmqYK51qD8Jfy+GUrzPHxN3Efbc12q8lf3CyJVlx5SCaeE yyTR10BkFHQeE4KhahwXsPuOaDPe+rBdNAWYOwCW6mxNfkOc3H8kz/nw9ziN3Td/B8 ccVLiR9YzBxtkhVjVtOTIIqYPB4+2MiBrqNyFMGGVzs2/Q+OeJiPYZYodODtGKExOQ eRaMsQXN36VQLRMi6tPFYVJJYI+AA75HN3DJf9l/fg/xDKdWUtd7iRuYq0d/eUxfZz YOYXIHDrJhrhA== 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 1/3] mm/damon/sysfs: check error from damon_sysfs_update_target() Date: Mon, 6 Nov 2023 23:34:06 +0000 Message-Id: <20231106233408.51159-2-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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 06 Nov 2023 15:34:18 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781859519664064307 X-GMAIL-MSGID: 1781859519664064307 damon_sysfs_update_target() returns error code for failures, but its caller, damon_sysfs_set_targets() is ignoring that. The update function seems making no critical change in case of such failures, but the behavior will look like DAMON sysfs is silently ignoring or only partially accepting the user input. Fix it. Fixes: 19467a950b49 ("mm/damon/sysfs: remove requested targets when online-commit inputs") Cc: # 5.19.x Signed-off-by: SeongJae Park --- Note that yet another fix[1] should be applied before this. [1] https://lore.kernel.org/all/739e6aaf-a634-4e33-98a8-16546379ec9f@moroto.mountain/ mm/damon/sysfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 1dfa96d4de99..7472404456aa 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1203,8 +1203,10 @@ static int damon_sysfs_set_targets(struct damon_ctx *ctx, damon_for_each_target_safe(t, next, ctx) { if (i < sysfs_targets->nr) { - damon_sysfs_update_target(t, ctx, + err = damon_sysfs_update_target(t, ctx, sysfs_targets->targets_arr[i]); + if (err) + return err; } else { if (damon_target_has_pid(ctx)) put_pid(t->pid); 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: 162230 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp2991854vqu; Mon, 6 Nov 2023 15:34:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IGeoEPsvtK5j+o7tQjnbZFSYWMeY+mNU2gaAKjxkX+J+Li8Q7mJcjcRGKkTNwRToW5tT0y7 X-Received: by 2002:a05:6358:2917:b0:168:dd37:172d with SMTP id y23-20020a056358291700b00168dd37172dmr38963955rwb.20.1699313661037; Mon, 06 Nov 2023 15:34:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699313660; cv=none; d=google.com; s=arc-20160816; b=cCOiNDKzz4CXXynI2ZYMupyom0koLfKEQlKJyNbTcsU+cui80GX0CfuXBOuCtTCzc0 gJr9rNryX1TnWOkAijbkSR2JU1mlgQCBxbtcu0gmFAuyQFUGB1aotcwVCtjBWbrcVfuw TedreKvyRNPTvQPjrJzzYiF3COI522oh1cEg/jfihjnnAVRU7/pa67J14QV0Fu6G5lwr kAXUO14vLAIInb6F2EV+Ax2cdfrBl5dW8PXivOugkQw+btm30ruHq7oeL4hJq1yI7GcU WtAHGPhWO+44cTNsm7xnzVTtlYAwNNG7YDR0K7oOY8QQJjShtK7sQ3mzdY4wgCK4Y/b7 l2WQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=w0kEAmDIiB+nNiOxil7eazkNdbm+gUZoY9qzJclbFfs=; fh=WXAAPMfSxLmsB2WJ8A0s7FPd+eTotx5bYas/XF5lzN4=; b=ZPFrAOrlalcbmu0H1zrJJRz3on1aCH440aLtcgWPfwVlLkbfcJx1n/vbBgo19pLWSK p2qhCYTT4Q7USE0s18BSR42cn2hvzZ6bthxdI63bBAIUI/Y4LL71OT3e6WOY99x778zm CIeuwic9PCSBGU+kt5ED7bbKH+XD53T66Z2+Cf2ESgBtofkhpMXZ3qPVHrp1+hvd4Mev RAXoNd+wjGCHBT9xN+cd3isBLDzjM5X7BoFe5xXMmjJyKYEosvtoaseHLIqyYJxz6hYL 2pUmknqscS8WCKg0wExEOkQrHCfGVNCQhhZYLUVprfSgc3onJBHU9tmrjKPb6liqeX9C iSZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=l7EqwQOv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id v10-20020a63610a000000b0058a4883e6casi789431pgb.225.2023.11.06.15.34.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 15:34:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=l7EqwQOv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 2D824810439B; Mon, 6 Nov 2023 15:34:20 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233412AbjKFXeR (ORCPT + 33 others); Mon, 6 Nov 2023 18:34:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233383AbjKFXeP (ORCPT ); Mon, 6 Nov 2023 18:34:15 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1C8583; Mon, 6 Nov 2023 15:34:12 -0800 (PST) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 06 Nov 2023 15:34:20 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781859521477232148 X-GMAIL-MSGID: 1781859521477232148 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; From patchwork Mon Nov 6 23:34:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 162231 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp2991891vqu; Mon, 6 Nov 2023 15:34:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IFKbz5VU8eS/1o2RWIDxRrjOZ4ShCSRVPLlIPmjTeiv0rnD+0o/aO0rGGcYpTRQ+s48orad X-Received: by 2002:a05:6e02:1d11:b0:352:a2f8:999a with SMTP id i17-20020a056e021d1100b00352a2f8999amr1463014ila.3.1699313667613; Mon, 06 Nov 2023 15:34:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699313667; cv=none; d=google.com; s=arc-20160816; b=sYjul97mBgbKNHbsXMMZ2t8P3/fETGcfMs046eWBAnzLNsK1QKOLzLybLGrQUU+Z8G nvDVZ9Du/4KaeZ5nZbqMdFGWTbX96bC3bSfcAtUAgjYV88+SdQrmDvmOqcKD7/rlcI7I N6q4czXux9Nby+j8wmVPf3Pb08g1C7WoBNY7fSSwIJswvramYWLxIAqj8JdP+5qvzcRn li0dj6t35CeqlYwoXMSOB3wRc8nVKJU7Vw3PgtZtXEvjoqeu1jpxQ+N7Xt6iK/G4O8VF QfurO7jNdy8XgApVr8SQua2+0HW8/gEnP7uK03vyjXVVCMA6NEgJ858Z6F/zQZmPkJpP 3s4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ED/5VRqDjeQ3vhbsBXBAmAewjBcby2wVIAxcWWWm3uU=; fh=WXAAPMfSxLmsB2WJ8A0s7FPd+eTotx5bYas/XF5lzN4=; b=zz9qcvY4Ud2eKqIKHeDyjaRSR+HxAEFTypPom31q5ETrDx727x38PSFa2PHWgmuzVz kxVzIvA/MBdwd44Hg/xlwVlU/SZKQ7NZWwX6fKJBaiqvBbfx8qQkQ7+wZDHrqvJ4VE/2 obuRnAAeRmMhXSzYdMx6P2lhB0eXjLWgejHCZTD/kv5vGuENJrKMJV+BGPTPZ9d7l4bt V/cHYkAeFNUV5GgJ6jWhqtCRrzxhF6EHFzsKvos8JixS9yxMK8eKS489t6MDzACcPVI4 zC+PRwkCrlqCRU4E91jG4Gefmt1+bQlHuMEZRSZUG8CaSIOydLUomboWTZL1GenNCTG1 8tHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=D1wTspPU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id bq7-20020a056a02044700b00578eafd0826si883112pgb.398.2023.11.06.15.34.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 15:34:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=D1wTspPU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 717FC81043B6; Mon, 6 Nov 2023 15:34:26 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233438AbjKFXeU (ORCPT + 33 others); Mon, 6 Nov 2023 18:34:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233321AbjKFXeQ (ORCPT ); Mon, 6 Nov 2023 18:34:16 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17C6983; Mon, 6 Nov 2023 15:34:14 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55F12C433CA; Mon, 6 Nov 2023 23:34:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699313653; bh=19smz8vjkknnlftKxQDFJP/XhxeknF20W/DyGkIS8Os=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D1wTspPUeGLo6x8Q/O1NGf9r8R7Y77Rea13Em+t/uPG+M8MB1RkYbqzvbkzEFu/2o +EbJZr5EpmuJNr37DT7pK4w7FQz0S3gGCgTdLEjwu0j0llYH7NAk8oU5KIZyMrGTDa xU8ou+PE7Hw8IjLv9dyB+hxXwQngY+1i+Ioz1CMmAr4QR9KqCjMOtErZW426EoDG0n ZWwH3Jx6nAAnd11/pOFJY9vSHUNoDTRFu1AngsTYsvE2korQlJDZmaQT6CsbPoIwr5 yzi1Mp+MivvdfbKoUGQsKHXEJT583q7JL2Znk9lwUlXiHrruB3lltIK3NLWFk4pDhE SzPy2Mk286CAw== 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 3/3] mm/damon/sysfs-schemes: handle tried region directory allocation failure Date: Mon, 6 Nov 2023 23:34:08 +0000 Message-Id: <20231106233408.51159-4-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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 06 Nov 2023 15:34:26 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781859528113413670 X-GMAIL-MSGID: 1781859528113413670 DAMON sysfs interface's before_damos_apply callback (damon_sysfs_before_damos_apply()), which creates the DAMOS tried regions for each DAMOS action applied region, is not handling the allocation failure for the sysfs directory data. As a result, NULL pointer derefeence is possible. Fix it by handling the case. Fixes: f1d13cacabe1 ("mm/damon/sysfs: implement DAMOS tried regions update command") Cc: # 6.2.x Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 7413cb35c5a9..be667236b8e6 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1826,6 +1826,8 @@ static int damon_sysfs_before_damos_apply(struct damon_ctx *ctx, return 0; region = damon_sysfs_scheme_region_alloc(r); + if (!region) + return 0; list_add_tail(®ion->list, &sysfs_regions->regions_list); sysfs_regions->nr_regions++; if (kobject_init_and_add(®ion->kobj,