Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1608481rwb; Thu, 15 Dec 2022 12:14:26 -0800 (PST) X-Google-Smtp-Source: AA0mqf5nmi3HBapCkSSV3sLSP1i/NEMw94t5bCFyjKHVbgLhjjOhO939UjEFksaw4vG3wwS4MuiQ X-Received: by 2002:a05:6a00:e8c:b0:575:f349:5971 with SMTP id bo12-20020a056a000e8c00b00575f3495971mr24883790pfb.33.1671135266272; Thu, 15 Dec 2022 12:14:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671135266; cv=none; d=google.com; s=arc-20160816; b=BSbI8DryltcTftdVSG9x+rYcpj1bx4aRHnuGiZodOni7rN3TaK84nnRtM2ojlG96pb B7LJPfbc9MADxbXYAiSIjH260U3XyWryJ4PyRWZ4lWP92eBo/iSjkPD7V1AUVXkuFi10 ZkSxXBlM1Rovh9YVBPtN3I1K4s4yS3juSZbqD1FOxL+ibyY6oTxvyNyu2l8LcA+IKu5p yTD34SnxByN/ZoMSfxKQzkrAAHG23liikhhZmaTDEVEKFoY4Q3/xSDLvhQTpohFN+wVe /euPTe8aNG4mHrztDYNTCuJTed/ERsKfykMlG5Pe+l16usD6269W0HrR2vUShkSPmFEe uM1A== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=/bpAfQgz00+RTQONa4kIrtddAiHdPbEvCVWs+HryZdI=; b=asWdSYNEbxTSOBpIW8QYjl7kQwKMHqd/ODPhHag+9RiUkJmwtyWERhmm19T/x5p4ed OePs61RKMO6jWN9RqTSklJSF66+OzGAEP0lhMnxhemv+aIB5ed669JZtnRc36m3fnPdB uQ1jgr/c/3oHbNHQ4XwdBz/q5UKILx+YAB0x3U7SybWRHmiGU5tEmNmY3Whck1ss+lot LXna0puDMje43N74L1/28hDIrtuW7wMpZApfIhvnH5Lo4LjcxJgUS1vmY7nYV7jqGw6k 6jYQheXOQlCA4tHcNXabce4CKMOmrAs0H/qAoTznRidl1Y8ELAWCQqfhQMEiu5ce0kuZ I55w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=ncnIb0Wf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f186-20020a6251c3000000b0057615c19064si62288pfb.42.2022.12.15.12.14.17; Thu, 15 Dec 2022 12:14:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=ncnIb0Wf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229965AbiLOTqr (ORCPT + 68 others); Thu, 15 Dec 2022 14:46:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229784AbiLOTqe (ORCPT ); Thu, 15 Dec 2022 14:46:34 -0500 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F2D252149; Thu, 15 Dec 2022 11:46:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1671133590; bh=vhXovAdMFvjGdI7fvSIRELXEjd78VENxVI/4IdKMMb8=; h=From:To:Cc:Subject:Date:From; b=ncnIb0WfhtEKF/kGA0uSnMmTXuI1l6JC9LQo0I6g4fETpGHCgxttX9WGWkYyDKqNd 9zcrYKXVjeuoDVDqA85XRhQxqgcVvDyAjDxyksOIqLj/L8vLnw2Nc3WXgHJ0lJwHNY 2lvDXcL7e0cY/5AVqL5qaJeMgecKnv1PxfWJ9GbQmi/UxORTXN5RCLaVTubrnzvhod 7rsyLENiWhIkh2pVtl2jN1FfUCDYW/xWglJjORi7zYr6C63AbyXAbqDWp2JmJaMh1H hoLjjwfTdeAtfpYLchBMfEFNFHv3wG7hX/sfEjeynMOzEMyeH+yn9jRp9K6hy+vGCk 8jJ3W40iqr5Rw== Received: from localhost.localdomain (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4NY2mQ0KT9zbb6; Thu, 15 Dec 2022 14:46:30 -0500 (EST) From: Mathieu Desnoyers To: Michal Hocko Cc: linux-kernel@vger.kernel.org, Mathieu Desnoyers , Randy Dunlap , "Huang, Ying" , "Aneesh Kumar K . V" , Dave Hansen , Feng Tang , Michal Hocko , Andrea Arcangeli , Mel Gorman , Mike Kravetz , Vlastimil Babka , Andi Kleen , Dan Williams , linux-api@vger.kernel.org, Andrew Morton , stable@vger.kernel.org Subject: [PATCH] mm/mempolicy: Fix memory leak in set_mempolicy_home_node system call Date: Thu, 15 Dec 2022 14:46:21 -0500 Message-Id: <20221215194621.202816-1-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS 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 When encountering any vma in the range with policy other than MPOL_BIND or MPOL_PREFERRED_MANY, an error is returned without issuing a mpol_put on the policy just allocated with mpol_dup(). This allows arbitrary users to leak kernel memory. Fixes: c6018b4b2549 ("mm/mempolicy: add set_mempolicy_home_node syscall") Signed-off-by: Mathieu Desnoyers Reviewed-by: Randy Dunlap Reviewed-by: "Huang, Ying" Reviewed-by: Aneesh Kumar K.V Acked-by: Michal Hocko Cc: Aneesh Kumar K.V Cc: Dave Hansen Cc: Feng Tang Cc: Michal Hocko Cc: Andrea Arcangeli Cc: Mel Gorman Cc: Mike Kravetz Cc: Randy Dunlap Cc: Vlastimil Babka Cc: Andi Kleen Cc: Dan Williams Cc: Huang Ying Cc: Cc: Andrew Morton Cc: stable@vger.kernel.org # 5.17+ --- mm/mempolicy.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 61aa9aedb728..02c8a712282f 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1540,6 +1540,7 @@ SYSCALL_DEFINE4(set_mempolicy_home_node, unsigned long, start, unsigned long, le * the home node for vmas we already updated before. */ if (new->mode != MPOL_BIND && new->mode != MPOL_PREFERRED_MANY) { + mpol_put(new); err = -EOPNOTSUPP; break; } -- 2.25.1