From patchwork Thu Nov 21 12:41:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeongjun Park X-Patchwork-Id: 13881982 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 95D78D6ED1D for ; Thu, 21 Nov 2024 12:41:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 34EB56B00A5; Thu, 21 Nov 2024 07:41:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2D6EB6B00A6; Thu, 21 Nov 2024 07:41:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 151196B00A8; Thu, 21 Nov 2024 07:41:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E06D96B00A5 for ; Thu, 21 Nov 2024 07:41:28 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 6ABC7ADEE2 for ; Thu, 21 Nov 2024 12:41:28 +0000 (UTC) X-FDA: 82810060368.13.0AC06AF Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf24.hostedemail.com (Postfix) with ESMTP id 86B3618001A for ; Thu, 21 Nov 2024 12:41:19 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=lQuD3gKY; spf=pass (imf24.hostedemail.com: domain of aha310510@gmail.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=aha310510@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732192735; 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:references:dkim-signature; bh=saHVPgloWCW73BS5krIAOvOiq0B6Gy9Xs2EnFsiEW50=; b=Ly/qTZNVKjZVHhgT3MCZxbIG6+6wfwMLY9Cgpjc05+Szksq+mLWk9KYi4xojyxYWYko5ZC Q7kkae7IwamtkYVPbt6MSXohJs2fFqGTQEa9yFizZCmTipzSW3HoisHv1bu+VetKc67XFk D0YY5L9lQBNQsYZ2aNmUDdJIoFQ2LjE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732192735; a=rsa-sha256; cv=none; b=PR6UXiQcRRN6FC5DX7majoUqBifbl3jw1GDImMV1jDlffEGDwJLLbQHThNZW3o8cYWUWYI eUD9t3WVqLMpdedTrLonhlfN+gpbkaJZ7WIpUDJbgFUzlA/Jd5xmdfGdDIZbaE2V876NY2 UK+6lKFiNeelTpIUS507o2hnM/J6CZ8= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=lQuD3gKY; spf=pass (imf24.hostedemail.com: domain of aha310510@gmail.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=aha310510@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-20cdb889222so7762685ad.3 for ; Thu, 21 Nov 2024 04:41:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732192885; x=1732797685; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=saHVPgloWCW73BS5krIAOvOiq0B6Gy9Xs2EnFsiEW50=; b=lQuD3gKYhdXvSHIrWWq9zAhx/Ay0Y7dfNRgVRHtey6I91AFqMDFENQUHgbrlYEKOh1 jLgDeJyLz73yN+Y33suVkOZsmtxamAv/mP+2j1Ptu3ks/tSpiA+kQHlQvpDjpIq8mXWa 78WMewY+MT4dRrKoWXT7HH9xF2JxIzUUlQhbh9r6rJuCVfYWKhRdWF8voVGb4V1NXS/L TaDYljP7OOLIBKnvDVuc/sGN9wR7swHLkpzWq0iGTSVVMmrAofXfZsJD1/p19LqxGmaA Qr1SGe4Mh31M2sJMPY0Y6z8bWui80QENFQCKZXfX2SPmoCzCZXbQISjCDXqrxX99je6p oErA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732192885; x=1732797685; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=saHVPgloWCW73BS5krIAOvOiq0B6Gy9Xs2EnFsiEW50=; b=bz5vFTkm+dEB7WbcH6ZzOxX50UJqVbc246u99Toc+ZsmPtKDLBfGzqSQrFoyg9oqnW eHSqpsEzc5z8vhzNH/jx7ifc9+B1kr7qonBjHEpBGsDlx0BY0C9EHAHwDSdFlziCgbAY j/jHZqjGSU14gdpL4k5rZkaJuDOS9bCUDJ8KJPrhoOda0VIhR4JRGdNrBo3KGeJvhtlU +KDE7/kwN1m7i6PkuEdqWzIrt/REQcfQ0HfAbjIGwJgb30qMbWlD02l4bWIQyru5v0uv 0S8Df8K7lNSIiVisHdTKnjh73bPXF4Av17CGUadRlbEQjBmQektyQcQ4BEY278+DG9O5 uAOA== X-Forwarded-Encrypted: i=1; AJvYcCUZaJ4i9CCKnMxnF4s0iHIc7Fj8na2ZGK5zbXUSIeCwDIIqUolXJwoddHYILcR9xpDiELtrKHqJ6w==@kvack.org X-Gm-Message-State: AOJu0YyOr1APLOdp6Qvt3VI+3n8pBBvsYmpxmYYTzDHFd7nEsppn7y1I u0DOqTdeV2I7dSw7L2HGi7PdtHQ2Nro++Y4Jub0fTAC4a60LmPx/ X-Google-Smtp-Source: AGHT+IHl71Cge81GkaeyNHyHp3L72kyzIqbjDHv1+AQUG60ivlEurQACwb+xPMKLWp5j7BQriPcwtw== X-Received: by 2002:a17:902:f652:b0:20c:d428:adf4 with SMTP id d9443c01a7336-2126a435e67mr96831535ad.38.1732192884795; Thu, 21 Nov 2024 04:41:24 -0800 (PST) Received: from kernelexploit-virtual-machine.localdomain ([121.185.186.233]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-212883f3298sm12589775ad.244.2024.11.21.04.41.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 04:41:24 -0800 (PST) From: Jeongjun Park To: akpm@linux-foundation.org Cc: dave@stgolabs.net, willy@infradead.org, Liam.Howlett@oracle.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Jeongjun Park Subject: [PATCH] mm/huge_memory: Fix to make vma_adjust_trans_huge() use find_vma() correctly Date: Thu, 21 Nov 2024 21:41:13 +0900 Message-Id: <20241121124113.66166-1-aha310510@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 86B3618001A X-Stat-Signature: nzfsieh6afk7pkzf5c4ud9mwxqy1szz1 X-HE-Tag: 1732192879-725095 X-HE-Meta: U2FsdGVkX1/YJ0q0i38sKiK+UOZYybFmvZeEozsxWlpiO2o/K8Db97E5Ck6KHnn1Z1oBCc386vdU0oOOsJZitI9ctzp7ZUqvMrfFC5J0wMu59LjFZawXjOUckLZMD/n+Z19MF/0d5NC4kZM+CxtP+EUnhMIjo4zt5r+PEwvECu5oj1dYWyVkeMETH4p03ZmDrohhIr878thLrYYpDUTIwv1nRCFrEb6NuERuxuuS9CwnoGTOKcwO16BZy3NCtfdqgwhnUK0ugRXqOPj0v9hzXrX6PxnL73+Ew/0DMglo/kDDKSuFQdEiOfkKlp58nsS+3IuGacM3p82UDEMMzily9UvVzTjso1ZdFxnj8uQyH06lMY4lxsVZU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ham, tests=bogofilter, spamicity=0.000003, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: vma_adjust_trans_huge() uses find_vma() to get the VMA, but find_vma() uses the returned pointer without any verification, even though it may return NULL. In this case, NULL pointer dereference may occur, so to prevent this, vma_adjust_trans_huge() should be fix to verify the return value of find_vma(). Cc: Fixes: 685405020b9f ("mm/khugepaged: stop using vma linked list") Signed-off-by: Jeongjun Park --- mm/huge_memory.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) -- diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 5734d5d5060f..db55b8abae2e 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2941,9 +2941,12 @@ void vma_adjust_trans_huge(struct vm_area_struct *vma, */ if (adjust_next > 0) { struct vm_area_struct *next = find_vma(vma->vm_mm, vma->vm_end); - unsigned long nstart = next->vm_start; - nstart += adjust_next; - split_huge_pmd_if_needed(next, nstart); + + if (likely(next)) { + unsigned long nstart = next->vm_start; + nstart += adjust_next; + split_huge_pmd_if_needed(next, nstart); + } } }