From patchwork Mon Jan 6 03:31:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 13926925 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 90333E77197 for ; Mon, 6 Jan 2025 03:31:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 029DA6B0082; Sun, 5 Jan 2025 22:31:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F1C516B0088; Sun, 5 Jan 2025 22:31:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE35D6B0089; Sun, 5 Jan 2025 22:31:48 -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 BED716B0082 for ; Sun, 5 Jan 2025 22:31:48 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 667E9C13E8 for ; Mon, 6 Jan 2025 03:31:48 +0000 (UTC) X-FDA: 82975602696.23.7E29BD2 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by imf20.hostedemail.com (Postfix) with ESMTP id BC6571C0007 for ; Mon, 6 Jan 2025 03:31:45 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="WuAwE/3u"; spf=pass (imf20.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736134306; 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=L52rvo+Xinet56DqCazfsooXe+eXMDS7wR/C1rggopk=; b=q6nqlJDAY2v/t/ka9xesa8g+anvrzIjfebZURqIlia1vQte51WcpyzjdVegglr6x2neg/1 bLNZQRVOIqZUpTqde7QSJe0c+pZhjVQ5N2CxDXpmHB5Dmbvy2pu/ZuQEPHFnVDrs8x8y4p YQn0exDZXT/pqGvTWWlaMMhhQmo2yhY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736134306; a=rsa-sha256; cv=none; b=0fsB52tnkt1Xw20/D3/uu239sv70TJNeKOaNEjHw7fU9PFt85JGzYUONyu+tp38YGJ/r0b r6VkWK+v8k/xhE4zdFKoiOAxrBfbKUPpPcabrNE/bYjkrKHYVDNgCRpipOt+qmBQSoBzYq cDV1D/4yCJdtxHZjCc1RedDWOJmmsbY= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="WuAwE/3u"; spf=pass (imf20.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-21628b3fe7dso191753735ad.3 for ; Sun, 05 Jan 2025 19:31:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1736134304; x=1736739104; 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=L52rvo+Xinet56DqCazfsooXe+eXMDS7wR/C1rggopk=; b=WuAwE/3u6e8G6A2kFWsQBz+1B5izgixvLgcibkRjOUWB8XtyLp9M0qAyAelFIUzodI cBAEy1BVxxt9KA+a4hfXTga16Uc5cDsRd0o5vASlUG95KO1fQDn1OB2LsoFjP8qXfKBs AwPe0pAcjtRXkgWhRQez0qh+3yRfnJPo8lIR5Dps2lYqPcXsiFp1ues2STS1vXvsl+LG ixvhMwkk9b/dkqm0T4PI2bskhQ2wZsGkpMpqvTBmh29DNTTolmj1IZVisTp9ZB1w7FQy +UOC51GHHw/VI3sZ7TIORMV5wl4lRxflaZSMkNlo3Nwv4Bnv/i/pY8ygoIN1nMvS3y2E pWDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736134304; x=1736739104; 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=L52rvo+Xinet56DqCazfsooXe+eXMDS7wR/C1rggopk=; b=bsDuczf2+oxKqmaR4eHgdRrv8FtXsGuouIWNYdYdGquctLAIkaQehmUxHFNyvv7dxY HAWOjnGhVsuAuhUXzjbl3vyM2MjIs6ZEO2dChHKIpVMEOUaiprL4lHu2huowoTQ8f0gm cXIGrQH6843HAUT6RfgdWY9Us2naxVcMgxgkksNx47lfIjEaiPzC/UpjdazXce0Rd93t guQv1pvAr/0h9mG52hi/a/VekxVp2EHPunxb2WKwA2t2O3004gVgH1H+cPcAWTMhScZn s2/MdlRb1F/bnip4MoM/893c4GJEWj4bbV9pHB5mQw+aYwvFp8TinmSz/8ZHv3m1d7An ojgQ== X-Gm-Message-State: AOJu0YxDe0Q7dRIxikjJd5ZRCIIXCrzydDSjJUJz3oTr0ncOn769g8zy h5NOxDSnn3ek+nsYYWhilRxBax02Z1ACdfZ7FtOhiS+UyNhT/MpqRicO3TloPp0= X-Gm-Gg: ASbGncvg0vWX2b4OvzwM4pKo99IdQtAqSGjAELjtjLZ92PPq5j8arnN5tOgtl9NIHEK 31ncRg2/UEvJJ0Tq0yDRRGCYcbzY5zp74b0Jng5yCnjXxIA40aJdybNMdzGE+TeqOnlFXbsYDCh OLxKDbURjhL35iopbyBF1dFCoUv0fkB7+SjIpnQtgJfa9+bf8sYTfymdIh3veh+oItDPvw5hozn cadFW6BMYU6nbXc2Po7qurhHJ85z9/JUwXB81mOsykpl7nItOf6LoJIKhd1VegKfhRoc6giKZi1 xcuk81rrA7ruLg== X-Google-Smtp-Source: AGHT+IHTDND3pNhNoEGlfFUQ2ez1LpWF/jUmJRoSp+psOxVg/ZgzMtJNsV0Qtt4Wu/gpBrf77MNeZA== X-Received: by 2002:a05:6a20:6f06:b0:1e1:b014:aec9 with SMTP id adf61e73a8af0-1e5e080c77fmr89285785637.29.1736134304340; Sun, 05 Jan 2025 19:31:44 -0800 (PST) Received: from PXLDJ45XCM.bytedance.net ([61.213.176.11]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad8dbb87sm30391698b3a.113.2025.01.05.19.31.40 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 05 Jan 2025 19:31:43 -0800 (PST) From: Muchun Song To: muchun.song@linux.dev, brauner@kernel.org, lihongbo22@huawei.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song , stable@vger.kernel.org, Cheung Wall Subject: [PATCH] hugetlb: fix NULL pointer dereference in trace_hugetlbfs_alloc_inode Date: Mon, 6 Jan 2025 11:31:17 +0800 Message-Id: <20250106033118.4640-1-songmuchun@bytedance.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) MIME-Version: 1.0 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: BC6571C0007 X-Stat-Signature: pa97b4us6k8zn59km3cq1rruaq4frp6g X-Rspam-User: X-HE-Tag: 1736134305-344025 X-HE-Meta: U2FsdGVkX18zcvvqbUBgsvsuCAomFdakDtQbEVjA+U4BRU+m3jKZzadwuZQpbyE1AL/zcPCVDmV+n0h3cnP4+YrPM9gT0DNnV+/gc+mpI4rRuzY/t/cwAgg9Yea+UHe+3xnW3hivfdlydiejvzw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7jpNO0uxfzwf7hBpRuq47hi+uAvW6ZgBmWsX20Bs3dOnSESSOq+9do8HzL5kcEaX/xl6lj0OSGREAyXdQITdOBp42jXp8kTM6hbB/NcB9P6a97GCydqaWLsqPfJGi1ILAaqe0U3vh6xKQakVBu4w8la5KRk1JUnpk2tCGRHjFDVhImmdvF6QwaPsyInSLetqLQQkUTC5cz5A7bnVnycgXzPKtY747bPR+yvc+pBOC15dZ6fknP0IjivTV 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: hugetlb_file_setup() will pass a NULL @dir to hugetlbfs_get_inode(), so we will access a NULL pointer for @dir. Fix it and set __entry->dr to 0 if @dir is NULL. Because ->i_ino cannot be 0 (see get_next_ino()), there is no confusing if user sees a 0 inode number. Fixes: 318580ad7f28 ("hugetlbfs: support tracepoint") Cc: stable@vger.kernel.org Reported-by: Cheung Wall Closes: https://lore.kernel.org/linux-mm/02858D60-43C1-4863-A84F-3C76A8AF1F15@linux.dev/T/# Signed-off-by: Muchun Song Reviewed-by: Hongbo Li --- include/trace/events/hugetlbfs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/trace/events/hugetlbfs.h b/include/trace/events/hugetlbfs.h index 8331c904a9ba8..59605dfaeeb43 100644 --- a/include/trace/events/hugetlbfs.h +++ b/include/trace/events/hugetlbfs.h @@ -23,7 +23,7 @@ TRACE_EVENT(hugetlbfs_alloc_inode, TP_fast_assign( __entry->dev = inode->i_sb->s_dev; __entry->ino = inode->i_ino; - __entry->dir = dir->i_ino; + __entry->dir = dir ? dir->i_ino : 0; __entry->mode = mode; ),