From patchwork Tue Jan 28 07:22:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sooraj X-Patchwork-Id: 13951708 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 AC30AC02188 for ; Mon, 27 Jan 2025 20:52:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 070A62801A9; Mon, 27 Jan 2025 15:52:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F3A9A2801A8; Mon, 27 Jan 2025 15:52:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB51A2801A9; Mon, 27 Jan 2025 15:52:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id BBE562801A8 for ; Mon, 27 Jan 2025 15:52:43 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 488711205D1 for ; Mon, 27 Jan 2025 20:52:43 +0000 (UTC) X-FDA: 83054430606.20.B40A57F Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf29.hostedemail.com (Postfix) with ESMTP id 7D35F120003 for ; Mon, 27 Jan 2025 20:52:41 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=IGv2cikf; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf29.hostedemail.com: domain of sooraj20636@gmail.com designates 209.85.214.182 as permitted sender) smtp.mailfrom=sooraj20636@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738011161; a=rsa-sha256; cv=none; b=3gb2GvFM2RN/BPTR3o6RIIDsEWk34gj0GquU2X5ElNMrXrtOjVucxH+PCpN/JEJqJNNndB M9E03UKv7jB6KKf+Is+3YK5JZwZM0o84UgpJH/WatrVp4gdAE/h4XIyUdKoHaZzWT/ivjx TMB/aF9slZRQ8XM6o16BcAIJfXnV0xM= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=IGv2cikf; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf29.hostedemail.com: domain of sooraj20636@gmail.com designates 209.85.214.182 as permitted sender) smtp.mailfrom=sooraj20636@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738011161; 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=QdZwXaBtnO7JEk3q3rzaKycB1rs/UoTn8f3CSb2vyMY=; b=BolMeV3KMHaAxiZXDQ8Rp8IITVIJ3DKqLwIzczUwU63ZvjLMRlnNAOGsdMbHXwiaNyv3Bg cRhByzpBH7R6tTG0rH5iwmW9GfiNq5p38PpR2pdaSNObaLV9/gyBwkvkKJ6HTorSVPT/+W fFcye3z6lJQ2nSo8iIxCorOVmYcNcII= Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-21c2f1b610dso114400995ad.0 for ; Mon, 27 Jan 2025 12:52:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738011160; x=1738615960; 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=QdZwXaBtnO7JEk3q3rzaKycB1rs/UoTn8f3CSb2vyMY=; b=IGv2cikfp/q/2IrA8wGKgbV5ElDzVwRugk0BE5jLRj9IDdyDXmfqPxQtvCik6yQ7ig 6dpSPFkFpjHBuIB/ivu+dQlwLaXKVeIID5tChe+/sO7O+CkO0NFup5fXXwcdVzHgvbSs 1GrLhvD3hWr8pJfsc+7z9bzLIDqT/Jr4G0ZTpyDXqT38bo3hs2NAZzxmrsQDUOvJDt2g 7k36i+M6PKVffLgetYTv4cNsKp4Kri+QXP6bqzjhhud9itLc5qLelkyck/bWn8yGdviD pirkpLHkWY8YME4098z1q9DlgAz/EQWC+16EPGIsbQRWxx04Oir6W56TQd92J2BOpbqx 2INw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738011160; x=1738615960; 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=QdZwXaBtnO7JEk3q3rzaKycB1rs/UoTn8f3CSb2vyMY=; b=syVX52+udSwnB8xrOWau6TnzbYwRWbaBmOKR9NEGI7r5zFIh7lrFRnBUJ2C/lyJdQe +sQjQp5t+3nnqFsExZZMUSgnpyyzTWOqQQDfO4Nf3jsTbN3BtBaCWS8f2Z18JUUWKpdB ofkBXlb4v7qQ/WQLBav2jEJJ9lkw85+G5zyaA1ZeQfjqazQExgpethGSiILiCRncf1H6 7dNe0suC3CgLpd9O3TFhcnkC0QxkctMCUbvfpkvg6UyP7LtKhhjXQIsUCREbfuopVp4W 9V8v3LY5APH7FgE7GlkLjuCD1Us7O3JZnXqWFQPiIaiGFuRpYpuuNEQsh8yR+wnoujr+ 8dNg== X-Gm-Message-State: AOJu0YyWh+vNuGGQQEY1iUpfLG5o1hCY9/8T5Q4S2YC+tSm7wZ+5tDKP 7hKHu0bzmNFpVapEMdR+3OXmu9rfW2v2GsQPCzPeP/J89QcjI0BrtImmX5Ax X-Gm-Gg: ASbGnctoU6UUFDaKPyYkyac0PVWlTQPmfyxaI8Ln6401RVQNdivBjrou0fG67HfrciS PwbVrMdJJ0kwRwDIJx69QbcwIkQYhshU9Xv8DZNYX1KdfKIAs25OsouO6lY/WWkF2pj4eu/HsBS /wkjnWhFjOH+/62klAyjfgS8At8aJ1vFpHoNaavFCquBicuFH31EhMTr2jH2kDC4ut7Vj4BeCHl ZAB7JnysPAeAtjlAFp8f3lIW7fX0OcY44CzAxORTmbfwws2MM7IWOv0bOOtYF3bos6tAPEdyFfy Zlmy X-Google-Smtp-Source: AGHT+IGqOpxem2P8RbvFJSp0dOKaAxVtc++SS5oGNuT4NsYxqXtgsqcUqcUbQ+WQWz6SMQnK7/nQ1w== X-Received: by 2002:a17:902:e54f:b0:21d:ccb9:e2b9 with SMTP id d9443c01a7336-21dccb9e40emr9818965ad.41.1738011159536; Mon, 27 Jan 2025 12:52:39 -0800 (PST) Received: from localhost ([112.133.252.44]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21da4141bfdsm67812035ad.118.2025.01.27.12.52.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2025 12:52:39 -0800 (PST) From: sooraj To: linux-mm@kvack.org Cc: sooraj Subject: [PATCH] mm/nommu: Fix NULL mm dereference in __vmalloc_user_flags Date: Tue, 28 Jan 2025 02:22:52 -0500 Message-ID: <20250128072252.10259-1-sooraj20636@gmail.com> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 7D35F120003 X-Rspamd-Server: rspam10 X-Stat-Signature: qoxcnieq1s88q5yt57cnhmcthod4gsy9 X-HE-Tag: 1738011161-458475 X-HE-Meta: U2FsdGVkX19nhian0dabCuj7E/qQgBLrZS//zbR2qtlXvsvK9hnaGw4HaqGVgtJiimexLQ+UeRKPLxLtI5I/VJQRwM7zOaFJrcv65VKqiFrAOADEEkM2nITbaBkdM+gSFl44xiG34cdNNvnDPMg7snG/hIfWZedx3bzDuyEuFY5gtT0Pf4BQpJNnBrcq8nusXQa40A5L1QRJuuVDOoQsrckK+v5Tpcp228rZZ0v55Uc/iRhpcxHmtw8l2CWU38vu9QqPdF9odv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SmUCrVHRR+gHIxEwhMKbqLxhDt90MeLTRliXcqiHD6yy2MqsKRYHAVXJ/3qfD/0QIXB/j36AX+w1fJxR74zbTdsFGS/gyOmn2V2sH48eWRYh35WvdlOB69iowM5w8iRWvyl88bMc0hyWxbz3TqZ0XqEsq2CNOhiXrl7+/8wpmFaLcRQ4MgI5teA2liAXAa75l3GyDyPMqOe6hH1K1pQNpDSYGAzpCbxTN5zsjijxd4SMj2Ci1FOIpOR+7srajQ9VSz12p2BfBipjW23t752xKKcWgCC/0KFztuYGLt+aQm+W18RW4x6ytogSt+Px7mRkQ5MdQF/ve/Mzzdh6Mm0FJuLNk4lIg== 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: Problem: The __vmalloc_user_flags() function attempts to acquire mmap_lock via current->mm without checking if the mm context exists. This causes a NULL pointer dereference when called from kernel threads (where current->mm == NULL), such as during filesystem operations. Fix: Add a NULL check for current->mm before attempting mmap_lock operations. Kernel threads don't have user memory mappings, so VM_USERMAP flag setting can be safely skipped in this context. Signed-off-by: sooraj --- mm/nommu.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/nommu.c b/mm/nommu.c index baa79abdaf03..df13c1c78d5b 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -152,6 +152,11 @@ static void *__vmalloc_user_flags(unsigned long size, gfp_t flags) ret = __vmalloc(size, flags); if (ret) { struct vm_area_struct *vma; + struct mm_struct *mm = current->mm; + + if(!mm){ + goto out; + } mmap_write_lock(current->mm); vma = find_vma(current->mm, (unsigned long)ret); @@ -160,6 +165,7 @@ static void *__vmalloc_user_flags(unsigned long size, gfp_t flags) mmap_write_unlock(current->mm); } + out: return ret; }