From nobody Wed Dec 17 17:59:40 2025 Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 69DF735961 for ; Wed, 18 Dec 2024 02:46:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734490001; cv=none; b=l2DKgGVZBdtFei6OfHVgj1dDhrX15fNoJDdU2+L5J80j4A+kFZHj/juFPjsILV3WgRUbni0cpWcUBNzgZ6RYAMyzWtybnh7eJtgPacTCRVHjFcCLsIjcOwi3VJEE+BuA7F5bRdWQFjP+RNd7DpO0ssk2kob9GfbNExd8LLAPXpY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734490001; c=relaxed/simple; bh=aVjAWPmpN5pMiHLjySSPOEhNa9jU4GgCs+y70Hqy8Qw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=iZisvfernIyk5aAbFawwWP4pupFReapqpB44UFRjizWgQTvpoRvuEGKRVUh+6w+feA8SV/aCEv0pVIigaq2c1ru98bzOXD085fhNv21TM5ZeVAGOV1jJWT1NCGrdZhKaxd2iX+DAcz/QCt+qrNg22JdkiZMdNdd1T7y5W4XHfDA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=m3NJAybV; arc=none smtp.client-ip=209.85.222.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="m3NJAybV" Received: by mail-qk1-f182.google.com with SMTP id af79cd13be357-7b15d7b7a32so607799185a.1 for ; Tue, 17 Dec 2024 18:46:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734489998; x=1735094798; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=/cwwt4OI5Akrv0c4PDqrh8w/sebwzMk0b3k7QNSWx64=; b=m3NJAybVFH2Hs2yJESgaZHdLisjjVAcPHnOt748C34YOKzaHPajsfbsJUagE4Imkll j7fUUbNOt4UVOZclwNchpdVGJRVlyo3SwmjBISMfyYZblQi+SQvPFM0F2PmyPsZQJQG1 UTB2SZ6Eeht5lRNUokjae5fPO/xSFxLpIfXrTRoVR9jz9KOsDIBdLlVW7ZbPZj6Gg5bA N/SGxPeaywdmCJi/xmWh5w/OkCCYyJsb5zvgJyblmD6nC0kySu8NXrZSYZlR60oDRNY6 ATKVy8eUfzCo7UiaNXqcex7k8fAg1JCCZwLXLUPVzcFzByzgYvfkNEP0+gQI8beWlDv7 wOMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734489998; x=1735094798; 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=/cwwt4OI5Akrv0c4PDqrh8w/sebwzMk0b3k7QNSWx64=; b=lLTZyIgFV4lYMeTaHFrqSem3Tbn1aTKSAe95861ANRmxv2sTADb184YUZ9hyVCXyxe fbI3Sphvc0hOIZLNmz+iP1s4a/5iiko3YUM3KBm7LcUqzoaE3ohlbvD7S3DbOMo4nrBP 1q5poAiqNlITB9IUMqWVVKowP1w7nh/CYlHNViVfhtcMmew7j+1vqBUf25CYq3CCM5bk urSRpwJ+6LYLMFl24uoDkG+XHOfQNQoB4eUlKNJTZt3l6hOYHYZfGTX7+BnDD55XY4Uv MZOD9r5rrRewZ0c6TaaR3tlWEcCA0L9zNvL0MOICY4sKbo4zOOq7K3km7zCtKfByJeSD gysw== X-Gm-Message-State: AOJu0Ywe8DNyfd+KvR+FHWVoczdVF/xOTFBP1xlDbDd8+xsV0RrdjbHG 0Qw8QilbYe2vjr+7Kg2hsghj27RRrAY1ZWtFLFl4dylddH6/8B1T X-Gm-Gg: ASbGncv4X3LCf9wIMsCWc0dVDoqxGFFsV+q0hGGB2RZFLzXlxoR8iZC8i4C5MAH4xXb X2pLoyl+l9IoiJrhXuSXWBK3vbk7wZHIZ2nab/RFF4+t60uzCLlGgLmvT+o3FBAGe4NsjrLJ/f9 WjNFW6oTrKMKpMXsj6R/ORQ6wP+Zlv+LIijaxS1gbHw5wKp4VhAUQJGatkwUji16vJtClqa3rza oMLHB79+S6uvlpVMAjb93oJ5YxRxj8QEkdgS3iVMDszoAKSD7Pg0FGQZJ7gq7TyGFuzJ7HAOLUB l0LU9n293qsHL/b3vJ8g3+TOP///OBEaGxk= X-Google-Smtp-Source: AGHT+IGrm4K99f6E1qzjgjS0RtGpY627b+HpPcNmVGE0n6AniA7Und5/IRrLba8Gcb27VOFTgzvwYA== X-Received: by 2002:a05:620a:29c9:b0:7b6:d70a:86df with SMTP id af79cd13be357-7b86374931dmr185835985a.27.1734489998314; Tue, 17 Dec 2024 18:46:38 -0800 (PST) Received: from localhost.localdomain (d24-150-189-55.home.cgocable.net. [24.150.189.55]) by smtp.googlemail.com with ESMTPSA id af79cd13be357-7b7047d4a20sm378840485a.39.2024.12.17.18.46.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Dec 2024 18:46:38 -0800 (PST) From: Dennis Lam To: mark@fasheh.com, jlbec@evilplan.org, joseph.qi@linux.alibaba.com Cc: linux-kernel@vger.kernel.org, ocfs2-devel@lists.linux.dev, Dennis Lam , syzbot+d173bf8a5a7faeede34c@syzkaller.appspotmail.com Subject: [PATCH v2] ocfs2: fix slab-use-after-free due to dangling pointer dqi_priv Date: Tue, 17 Dec 2024 21:39:25 -0500 Message-ID: <20241218023924.22821-2-dennis.lamerice@gmail.com> X-Mailer: git-send-email 2.47.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When mounting ocfs2 and then remounting it as read-only, a slab-use-after-free occurs after the user uses a syscall to quota_getnextquota. Specifically, sb_dqinfo(sb, type)->dqi_priv is the dangling pointer. During the remounting process, the pointer dqi_priv is freed but is never set as null leaving it to to be accessed. Additionally, the read-only option for remounting sets the DQUOT_SUSPENDED flag instead of setting the DQUOT_USAGE_ENABLED flags. Moreover, later in the process of getting the next quota, the function ocfs2_get_next_id is called and only checks the quota usage flags and not the quota suspended flags. To fix this, I set dqi_priv to null when it is freed after remounting with read-only and put a check for DQUOT_SUSPENDED in ocfs2_get_next_id. Signed-off-by: Dennis Lam Reported-by: syzbot+d173bf8a5a7faeede34c@syzkaller.appspotmail.com Tested-by: syzbot+d173bf8a5a7faeede34c@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/6731d26f.050a0220.1fb99c.014b.GAE@googl= e.com/T/ Reviewed-by: Joseph Qi --- Changes in v2: - replaced dquot suspended check with !sb_has_quota_active instead - link to v1: https://lore.kernel.org/lkml/20241215035828.106936-2-dennis.l= americe@gmail.com/ fs/ocfs2/quota_global.c | 2 +- fs/ocfs2/quota_local.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/ocfs2/quota_global.c b/fs/ocfs2/quota_global.c index 2b0daced98eb..096b799d60a0 100644 --- a/fs/ocfs2/quota_global.c +++ b/fs/ocfs2/quota_global.c @@ -893,7 +893,7 @@ static int ocfs2_get_next_id(struct super_block *sb, st= ruct kqid *qid) int status =3D 0; =20 trace_ocfs2_get_next_id(from_kqid(&init_user_ns, *qid), type); - if (!sb_has_quota_loaded(sb, type)) { + if (!sb_has_quota_active(sb, type)){ status =3D -ESRCH; goto out; } diff --git a/fs/ocfs2/quota_local.c b/fs/ocfs2/quota_local.c index 73d3367c533b..2956d888c131 100644 --- a/fs/ocfs2/quota_local.c +++ b/fs/ocfs2/quota_local.c @@ -867,6 +867,7 @@ static int ocfs2_local_free_info(struct super_block *sb= , int type) brelse(oinfo->dqi_libh); brelse(oinfo->dqi_lqi_bh); kfree(oinfo); + info->dqi_priv =3D NULL; return status; } =20 --=20 2.47.0