From patchwork Tue Oct 1 09:00:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 13817671 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F126519D07A; Tue, 1 Oct 2024 09:11:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=35.157.23.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727773872; cv=none; b=NT/Sr6jPbMVSxahl7Zgo3gmPhJDSwW3Nlo/SSzn3ScQrrOFS1cPl+FASemZYvAV8r/tyq3DxE/PvB0wpmHlSMF+Wjug5NOWqcGJrXag8Xf6CcDjtWDNZP2P1HRGB5PPTc4aCeu2BvdYUptPGuq9VeLqqfhgelN9I6H6LHgFnJbg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727773872; c=relaxed/simple; bh=PXZWLLFPWp/92qDLEEuKXg3jIukh0rUF6VWNzKglr8g=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=j6wo/aOT2yEnf/y/sGMOoQGgZaYQFryltW8NDTjMDUTzQu0shFd7smVD/MDz2RZh+BKYz/Qdmi62p0aBqq9apsC8/EUOJE9gFauSAqPdOsIlZyzRcodqaESuD8P6rrcmfVUy0Vqdd7gQaUoj6mdV2Hi8MockGx4T2Xc4kK3MfyQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com; spf=pass smtp.mailfrom=paragon-software.com; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b=n3O+NARF; arc=none smtp.client-ip=35.157.23.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b="n3O+NARF" Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 140F721B6; Tue, 1 Oct 2024 08:53:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1727772832; bh=iKaPySfEN18SNnEH2EvYXCsXO65BKve1de0WsdZe3eI=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=n3O+NARFD1NJnlupRJRoDOZU4cHY6zKYIhQ5CSMBVm7XcNYbdqUXTssJWU0AGVPUv OXLDtRmFWut5fItxd3UC1UuY44pcdb5mATuVRHVuLtS3p3DoNTN5h3ctBb7f1o34Kx LA28CDtX3xs31tNJDy5+KY9di+Gegj+cnbuMtzmg= Received: from ntfs3vm.paragon-software.com (192.168.211.162) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Tue, 1 Oct 2024 12:01:25 +0300 From: Konstantin Komarov To: CC: , , Konstantin Komarov , Subject: [PATCH 1/6] fs/ntfs3: Fix possible deadlock in mi_read Date: Tue, 1 Oct 2024 12:00:59 +0300 Message-ID: <20241001090104.15313-2-almaz.alexandrovich@paragon-software.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241001090104.15313-1-almaz.alexandrovich@paragon-software.com> References: <20241001090104.15313-1-almaz.alexandrovich@paragon-software.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: vobn-exch-01.paragon-software.com (172.30.72.13) To vdlg-exch-02.paragon-software.com (172.30.1.105) Mutex lock with another subclass used in ni_lock_dir(). Reported-by: syzbot+bc7ca0ae4591cb2550f9@syzkaller.appspotmail.com Signed-off-by: Konstantin Komarov --- fs/ntfs3/namei.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ntfs3/namei.c b/fs/ntfs3/namei.c index 4c35262449d7..abf7e81584a9 100644 --- a/fs/ntfs3/namei.c +++ b/fs/ntfs3/namei.c @@ -81,7 +81,7 @@ static struct dentry *ntfs_lookup(struct inode *dir, struct dentry *dentry, if (err < 0) inode = ERR_PTR(err); else { - ni_lock(ni); + ni_lock_dir(ni); inode = dir_search_u(dir, uni, NULL); ni_unlock(ni); } From patchwork Tue Oct 1 09:01:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 13817675 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0896F19D090; Tue, 1 Oct 2024 09:11:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=35.157.23.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727773873; cv=none; b=mFmu4qHC2Fosc5M9qUJ1EhQvf1pFo3TqWKeJGHkYnnVV9HC9JrN8hoFyivs8jMa0H5QIZECm8TSZ/T0giRH09qReRpMhLCJ9qX/bVy/DDyIyBtc5vJaTg2iwYuORmxO+wKwWQW4FUSiYtu5qxXS88+JSvdafR2nN+KHYLAxdmI4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727773873; c=relaxed/simple; bh=lAKuALHKzZtCcrl0kxZtaUCqo8Eoo6FfNB9E6g7p9TE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UexltbP/owy4HYRnyAHoiF1G+lQ90dD5ha+FJ7VZLoFM09EnT8MNlG8yPDkeApNDWPE1UWioUQXVnrZPmbU1Jevp51Yh/grJOY+eA/Dson7XO1UFH2zp6de6I5fhpMj72in/GvgYO42eY1tGP5SJMSYqQNvX1wWl8BqxK4loDAo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com; spf=pass smtp.mailfrom=paragon-software.com; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b=FBFjD67p; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b=jsfhYNx2; arc=none smtp.client-ip=35.157.23.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b="FBFjD67p"; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b="jsfhYNx2" Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id C1F8121B8; Tue, 1 Oct 2024 08:53:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1727772832; bh=oUMBbVWITqGhjFAASrazf2BjnWcJotBaiYZTDmTKvVE=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=FBFjD67p/ezfyu4CI8p+fCmvNF6BD7FUWkcLzuppKutWdlPL9ooDx6UqgxFMzgXYo gFocO3Xpar52HzqbGCGM4U1zog1zfgMfjJGMiEG9ns3VZlM1nV9aeeYLVbvfmXoTRo gGTI1aMQgg2BYe9FsEjGuQ6NfVipUcTsKuSh/5wE= Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayfre-01.paragon-software.com (Postfix) with ESMTPS id 7238C21F1; Tue, 1 Oct 2024 09:01:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1727773286; bh=oUMBbVWITqGhjFAASrazf2BjnWcJotBaiYZTDmTKvVE=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=jsfhYNx20aZJOkM6hxkmIzdlDPkZIYLfv2/VLc/JgGySYioVvaISSP/h6QRGCcAgq 7AlDZzhHFBxco9cOrvDB3faENsBg+WOdplgmsitqaSZ9Gq4gSCIlkeq/Kq29kp+rjb ZgcsbpRJAzY8y8SPbxEwkka1vBjNJC6boVHRFjvM= Received: from ntfs3vm.paragon-software.com (192.168.211.162) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Tue, 1 Oct 2024 12:01:25 +0300 From: Konstantin Komarov To: CC: , , Konstantin Komarov , Subject: [PATCH 2/6] fs/ntfs3: Additional check in ni_clear() Date: Tue, 1 Oct 2024 12:01:00 +0300 Message-ID: <20241001090104.15313-3-almaz.alexandrovich@paragon-software.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241001090104.15313-1-almaz.alexandrovich@paragon-software.com> References: <20241001090104.15313-1-almaz.alexandrovich@paragon-software.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: vobn-exch-01.paragon-software.com (172.30.72.13) To vdlg-exch-02.paragon-software.com (172.30.1.105) Checking of NTFS_FLAGS_LOG_REPLAYING added to prevent access to uninitialized bitmap during replay process. Reported-by: syzbot+3bfd2cc059ab93efcdb4@syzkaller.appspotmail.com Signed-off-by: Konstantin Komarov --- fs/ntfs3/frecord.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/ntfs3/frecord.c b/fs/ntfs3/frecord.c index 7d4e54161291..41c7ffad2790 100644 --- a/fs/ntfs3/frecord.c +++ b/fs/ntfs3/frecord.c @@ -102,7 +102,9 @@ void ni_clear(struct ntfs_inode *ni) { struct rb_node *node; - if (!ni->vfs_inode.i_nlink && ni->mi.mrec && is_rec_inuse(ni->mi.mrec)) + if (!ni->vfs_inode.i_nlink && ni->mi.mrec && + is_rec_inuse(ni->mi.mrec) && + !(ni->mi.sbi->flags & NTFS_FLAGS_LOG_REPLAYING)) ni_delete_all(ni); al_destroy(ni); From patchwork Tue Oct 1 09:01:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 13817672 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1974B19D09D; Tue, 1 Oct 2024 09:11:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=35.157.23.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727773872; cv=none; b=eyX4OBHArEyZLHd9hQGFxEXeWL7Th1NS10Fmjf7im3OQIVjx0XXlsOUK7FJdK+2z295wYLzBi2sdfXLTsRjXfAyGLJlAqmIELgRxewHA3ad5yvIVqOL+hDjPH4Sxg847+IpYVZqtCRCHcTlnGC1dPnVzVwRqP4jZGl39gWUIgRs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727773872; c=relaxed/simple; bh=Np8uxb82WjqCqAHczCUqm9zGpxcxVDATjiaqYgBCXUw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pDp8Jhnvm0h7oL5Tb7bIpmEDC8M+ix3cMM2hU9+BUPYSEwGsb1E87IzkpmjRuUpqM/qHeDV0ElX8J1qT7MQAEiewSYDxUH52lVZAEhhTT0hAnga/MGNPjHQBv+IJkPQVKICQVZzHQWsE53JiTAYc7LfGCTvOjd1UsI7+b6sf7Dc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com; spf=pass smtp.mailfrom=paragon-software.com; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b=PXi81XRX; arc=none smtp.client-ip=35.157.23.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b="PXi81XRX" Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 68A0221B9; Tue, 1 Oct 2024 08:53:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1727772833; bh=SLgx5JiLnCawPFqRiV5IdAXRHlU6ft555LdTRa/w6wI=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=PXi81XRXHH7CjdXQo/+33F4bfy4kGj5LMlZDJHXGsSOoMXP0JhxbGtcctCVRPQHJe ubIyZYdAakaBfC8wjuFqSh8RB6KsHq+80NODrIdLVdtHtu6gFNdhMoZnB+H3FK+Arz dpqHSnRBEC007ysO1sT8jbbzEyx0WqdFsDpVLX+s= Received: from ntfs3vm.paragon-software.com (192.168.211.162) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Tue, 1 Oct 2024 12:01:26 +0300 From: Konstantin Komarov To: CC: , , Konstantin Komarov Subject: [PATCH 3/6] fs/ntfs3: Sequential field availability check in mi_enum_attr() Date: Tue, 1 Oct 2024 12:01:01 +0300 Message-ID: <20241001090104.15313-4-almaz.alexandrovich@paragon-software.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241001090104.15313-1-almaz.alexandrovich@paragon-software.com> References: <20241001090104.15313-1-almaz.alexandrovich@paragon-software.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: vobn-exch-01.paragon-software.com (172.30.72.13) To vdlg-exch-02.paragon-software.com (172.30.1.105) The code is slightly reformatted to consistently check field availability without duplication. Fixes: 556bdf27c2dd ("ntfs3: Add bounds checking to mi_enum_attr()") Signed-off-by: Konstantin Komarov --- fs/ntfs3/record.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/fs/ntfs3/record.c b/fs/ntfs3/record.c index 427c71be0f08..f810f0419d25 100644 --- a/fs/ntfs3/record.c +++ b/fs/ntfs3/record.c @@ -237,6 +237,7 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr) } /* Can we use the first field (attr->type). */ + /* NOTE: this code also checks attr->size availability. */ if (off + 8 > used) { static_assert(ALIGN(sizeof(enum ATTR_TYPE), 8) == 8); return NULL; @@ -257,10 +258,6 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr) return NULL; asize = le32_to_cpu(attr->size); - if (asize < SIZEOF_RESIDENT) { - /* Impossible 'cause we should not return such attribute. */ - return NULL; - } /* Check overflow and boundary. */ if (off + asize < off || off + asize > used) @@ -290,6 +287,10 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr) if (attr->non_res != 1) return NULL; + /* Can we use memory including attr->nres.valid_size? */ + if (asize < SIZEOF_NONRESIDENT) + return NULL; + t16 = le16_to_cpu(attr->nres.run_off); if (t16 > asize) return NULL; @@ -316,7 +317,8 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr) if (!attr->nres.svcn && is_attr_ext(attr)) { /* First segment of sparse/compressed attribute */ - if (asize + 8 < SIZEOF_NONRESIDENT_EX) + /* Can we use memory including attr->nres.total_size? */ + if (asize < SIZEOF_NONRESIDENT_EX) return NULL; tot_size = le64_to_cpu(attr->nres.total_size); @@ -326,9 +328,6 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr) if (tot_size > alloc_size) return NULL; } else { - if (asize + 8 < SIZEOF_NONRESIDENT) - return NULL; - if (attr->nres.c_unit) return NULL; From patchwork Tue Oct 1 09:01:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 13817673 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1821D19D09C; Tue, 1 Oct 2024 09:11:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=35.157.23.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727773872; cv=none; b=arW8xrsHOY2Nw2zhvwvfXL7GbqM5gXTPbNGowu0gg4EGtEhjdlio8xnXbuGop5xBPW3npkBdNyFW52AoF73MdBMLhiNnp5zqzfXcasozfK1JP0Uq1nAIzKWUz4tl+FhAwswYTjhvqlgdVKQP6SVwjBxRx2ovAbMoSGRRGOC6260= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727773872; c=relaxed/simple; bh=Aq8rlex9plu17O93Y02qKf6CqtUUO6dcSbSp3Q0dCkE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=G8viWWHlXWv9AYHLOvRsTRblJ50EE/xA6Ix7NCttUDmRHGWlmgKsaKyY5mv4oJ0cHcA7FBgy72KpSLMj+GHpJuyYJgCZBoEPBMMVinGnLcRA+PzwOLulnGPiM+vssh8xh1ZwdbZ0uSi2l10G3VraKst2T6pYFcEH0FHqbgzvc8k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com; spf=pass smtp.mailfrom=paragon-software.com; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b=mj9MBD6h; arc=none smtp.client-ip=35.157.23.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b="mj9MBD6h" Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 94F3E21BA; Tue, 1 Oct 2024 08:53:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1727772833; bh=e/jxg4L2Jqrti7kGJ1jq2Z5/4N2btjuaQe4g4VrM1Fc=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=mj9MBD6h6ylJa+2MoA2r/z3nZ4v8dD3WCyAuzerSCHad3rMphGpl6FCkR5yz5vH7Y ckB8tfLyACTAIWZWql9ZylSwBV6ejH8XFWK+G3kPp/zUgLIW6CNCVk2pej/JTr6JAE 6bpqZUdR06vQdpiMWaU1Vr3/xdRo9fMh5xzOtzwM= Received: from ntfs3vm.paragon-software.com (192.168.211.162) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Tue, 1 Oct 2024 12:01:27 +0300 From: Konstantin Komarov To: CC: , , Konstantin Komarov , Subject: [PATCH 4/6] fs/ntfs3: Fix general protection fault in run_is_mapped_full Date: Tue, 1 Oct 2024 12:01:02 +0300 Message-ID: <20241001090104.15313-5-almaz.alexandrovich@paragon-software.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241001090104.15313-1-almaz.alexandrovich@paragon-software.com> References: <20241001090104.15313-1-almaz.alexandrovich@paragon-software.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: vobn-exch-01.paragon-software.com (172.30.72.13) To vdlg-exch-02.paragon-software.com (172.30.1.105) Fixed deleating of a non-resident attribute in ntfs_create_inode() rollback. Reported-by: syzbot+9af29acd8f27fbce94bc@syzkaller.appspotmail.com Signed-off-by: Konstantin Komarov --- fs/ntfs3/inode.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c index 81746a959b47..5dc261404957 100644 --- a/fs/ntfs3/inode.c +++ b/fs/ntfs3/inode.c @@ -1718,7 +1718,10 @@ int ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir, attr = ni_find_attr(ni, NULL, NULL, ATTR_EA, NULL, 0, NULL, NULL); if (attr && attr->non_res) { /* Delete ATTR_EA, if non-resident. */ - attr_set_size(ni, ATTR_EA, NULL, 0, NULL, 0, NULL, false, NULL); + struct runs_tree run; + run_init(&run); + attr_set_size(ni, ATTR_EA, NULL, 0, &run, 0, NULL, false, NULL); + run_close(&run); } if (rp_inserted) From patchwork Tue Oct 1 09:01:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 13817665 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C0BF419ABCB; Tue, 1 Oct 2024 09:01:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=35.157.23.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727773296; cv=none; b=XHCz6ghuIkGj4ONj9o2JjV8a5DJEDKC8yFn4vVbyYIJMsSZhCtjuCBXDXXPjiHjOn1vl+T6155YzxAISpx3LddR8E87/UwLFWgpRa6384Jll9LKwEzyvyrLhjQCsUWYvWboDQe83p/cgslJ3lNEnYQpY228RrW2rTvXnhFqLFWs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727773296; c=relaxed/simple; bh=qWjK1RsYyKSUzUBD+yADyl36UD/grgHqx9G+jDdtfTw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DVnRqae6Q0EwyYN+AgH8sG25Vz9w1bkXHaAJlgp5jfgQKR9IqwnlRo2X7mhoOIjqTBsMGI0BPOyeacBFaJSKv4UB1WDw91jv1CM4az6KubRyi511aRQ8BhvjlxLeOtKa9GwPyBZqCuWxeDCT5GGclIk9JIICxOS6XsEkiLkI0IA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com; spf=pass smtp.mailfrom=paragon-software.com; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b=CeRRCjfZ; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b=EoPstPcs; arc=none smtp.client-ip=35.157.23.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b="CeRRCjfZ"; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b="EoPstPcs" Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 7B57C21BC; Tue, 1 Oct 2024 08:53:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1727772834; bh=jlLbgdrAfNBCBg4R6vHQVbLSiuo7T5iPhjtMGiclWGM=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=CeRRCjfZzk2Ad3xaHUT7Su/DgIFcCYGDAF/u4VnXHHCAZKzdAYmzJAKsZf/HitWBC tK5DhdMMGOwFH2M42QdHVQOnzURC38szVhT2MRdZCLF2Kfu4VqBEmwv9RPp57QI9Bi 61HVMOvXit6m/zsjdzZsisNiMllfpSie+oYO5mJw= Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayfre-01.paragon-software.com (Postfix) with ESMTPS id 2A9DD21F1; Tue, 1 Oct 2024 09:01:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1727773288; bh=jlLbgdrAfNBCBg4R6vHQVbLSiuo7T5iPhjtMGiclWGM=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=EoPstPcsAfFq5iDPvzGV0uNhZ84UO8sizoPpH7OfPq03zCeaTK0suh4mLRBuZBjo9 oYglpsHbzwx7kljUDHauMtXwbWwsNKtORuqC0IZrQtXOqjb+ey+rZG3b6uaX+E3KWQ XaR0GNZrxRqhH2uCW1MH6Vmqh1sm8ozhauF9OrHA= Received: from ntfs3vm.paragon-software.com (192.168.211.162) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Tue, 1 Oct 2024 12:01:27 +0300 From: Konstantin Komarov To: CC: , , Konstantin Komarov , Subject: [PATCH 5/6] fs/ntfs3: Additional check in ntfs_file_release Date: Tue, 1 Oct 2024 12:01:03 +0300 Message-ID: <20241001090104.15313-6-almaz.alexandrovich@paragon-software.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241001090104.15313-1-almaz.alexandrovich@paragon-software.com> References: <20241001090104.15313-1-almaz.alexandrovich@paragon-software.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: vobn-exch-01.paragon-software.com (172.30.72.13) To vdlg-exch-02.paragon-software.com (172.30.1.105) Reported-by: syzbot+8c652f14a0fde76ff11d@syzkaller.appspotmail.com Signed-off-by: Konstantin Komarov --- fs/ntfs3/file.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c index 4fdcb5177ea1..eb935d4180c0 100644 --- a/fs/ntfs3/file.c +++ b/fs/ntfs3/file.c @@ -1314,7 +1314,14 @@ static int ntfs_file_release(struct inode *inode, struct file *file) /* If we are last writer on the inode, drop the block reservation. */ if (sbi->options->prealloc && ((file->f_mode & FMODE_WRITE) && - atomic_read(&inode->i_writecount) == 1)) { + atomic_read(&inode->i_writecount) == 1) + /* + * The only file when inode->i_fop = &ntfs_file_operations and + * init_rwsem(&ni->file.run_lock) is not called explicitly is MFT. + * + * Add additional check here. + */ + && inode->i_ino != MFT_REC_MFT) { ni_lock(ni); down_write(&ni->file.run_lock); From patchwork Tue Oct 1 09:01:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 13817666 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C0C3D19B3C1; Tue, 1 Oct 2024 09:01:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=35.157.23.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727773296; cv=none; b=DokVmJ3Dgwl9Kd3eHKD1hUjCl8hHmW5Z4NRbfXtEpp1lU7IlcGpXUW7oGApC6Nd4kca5jMeKiXMKen5ahVRX+0i32YkHH+eSyGGTvFhJrV5YJGV5FuSWstmcez1G4fPRpI+EHKRvByTVieUseXOgh+L3x7+oe1bzsh2dtGbbJoo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727773296; c=relaxed/simple; bh=Hwgi/y5Dk7t34WtuR23fuoxzTvfdQf0eldBit/gselk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ApVcoguMa76VicFewAh1R+tPcY2jn3Go8b8RWVOhhWisNtqRJivJ1tGorW3T5NXirc6E8z+eHZsWcMbTYpBowaq71L0qmocb4EqKLQs2Ha+2PWvUCsahImXeZ0sUeVaXbYsPVvdahN7pwxlqbOSTyeT3N0NM4/5Q7SIebPlWAxI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com; spf=pass smtp.mailfrom=paragon-software.com; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b=QGRjrPut; arc=none smtp.client-ip=35.157.23.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b="QGRjrPut" Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id DC6F421BD; Tue, 1 Oct 2024 08:53:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1727772834; bh=8qucmwn+c7J8uqN629Lesahfgqjtj3mJT43MI9cKjFs=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=QGRjrPutmJx4gKxcYgWdJ5oT9s4pIinErKE1CcDGyp2+IqNvGDmUZZJjzg45uR7Tl D0t9hevzWxazyjYT12t0/piMxj5RSaox4Fk0un4v2HkOeWkhJKBvbMQx7KRRHFnOT+ wMr473R1RQjU+TR4bcqXJv/RR90mhtxEWpLhaPuc= Received: from ntfs3vm.paragon-software.com (192.168.211.162) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Tue, 1 Oct 2024 12:01:28 +0300 From: Konstantin Komarov To: CC: , , Konstantin Komarov Subject: [PATCH 6/6] fs/ntfs3: Format output messages like others fs in kernel Date: Tue, 1 Oct 2024 12:01:04 +0300 Message-ID: <20241001090104.15313-7-almaz.alexandrovich@paragon-software.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241001090104.15313-1-almaz.alexandrovich@paragon-software.com> References: <20241001090104.15313-1-almaz.alexandrovich@paragon-software.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: vobn-exch-01.paragon-software.com (172.30.72.13) To vdlg-exch-02.paragon-software.com (172.30.1.105) Signed-off-by: Konstantin Komarov --- fs/ntfs3/super.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c index 128d49512f5d..6a0f6b0a3ab2 100644 --- a/fs/ntfs3/super.c +++ b/fs/ntfs3/super.c @@ -90,7 +90,7 @@ void ntfs_printk(const struct super_block *sb, const char *fmt, ...) level = printk_get_level(fmt); vaf.fmt = printk_skip_level(fmt); vaf.va = &args; - printk("%c%cntfs3: %s: %pV\n", KERN_SOH_ASCII, level, sb->s_id, &vaf); + printk("%c%cntfs3(%s): %pV\n", KERN_SOH_ASCII, level, sb->s_id, &vaf); va_end(args); } @@ -124,10 +124,15 @@ void ntfs_inode_printk(struct inode *inode, const char *fmt, ...) struct dentry *de = d_find_alias(inode); if (de) { + int len; spin_lock(&de->d_lock); - snprintf(name, sizeof(s_name_buf), " \"%s\"", - de->d_name.name); + len = snprintf(name, sizeof(s_name_buf), " \"%s\"", + de->d_name.name); spin_unlock(&de->d_lock); + if (len <= 0) + name[0] = 0; + else if (len >= sizeof(s_name_buf)) + name[sizeof(s_name_buf) - 1] = 0; } else { name[0] = 0; } @@ -140,7 +145,7 @@ void ntfs_inode_printk(struct inode *inode, const char *fmt, ...) vaf.fmt = printk_skip_level(fmt); vaf.va = &args; - printk("%c%cntfs3: %s: ino=%lx,%s %pV\n", KERN_SOH_ASCII, level, + printk("%c%cntfs3(%s): ino=%lx,%s %pV\n", KERN_SOH_ASCII, level, sb->s_id, inode->i_ino, name ? name : "", &vaf); va_end(args);