Received: by 2002:ab2:687:0:b0:1f4:6588:b3a7 with SMTP id s7csp39407lqe; Tue, 9 Apr 2024 13:47:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXPgXnKAH2xBEpV+rdOlYXckUi5w0CNs9S9Elc9RVkJLeEp87vi4eCxoFrExTHP4oqkM593vdUlkallWz0YX1RtRCJhpVR4v1qtxomw9Q== X-Google-Smtp-Source: AGHT+IHEUDMCGm7adL5e8Spw2Jwskwxkx1dGmU2ETG9Jx8BxZ/qbu4uXK4AnQicKDXrNBL3D+veN X-Received: by 2002:a05:6808:3b7:b0:3c5:f77e:6133 with SMTP id n23-20020a05680803b700b003c5f77e6133mr612022oie.34.1712695628104; Tue, 09 Apr 2024 13:47:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712695628; cv=pass; d=google.com; s=arc-20160816; b=rcolpVg4f3vX0n13uxvnFEzTUxaFiPoRiFPLQ5jm3qm7YFhVg3eee8V9VY+FKc2hn+ LURHoU3OmzEPebWdFF7UFuTPUnTtC70CSz0eIPEdKzn6kt3bZpA30Ccagp08iF+bgnTV DtoP7r3KIfp0WCY9y36i7LJEbh89FPbjUqgHzhe7upzQUzSTgbznu3NM46EanTsCFlqO T0yw0DiFp69gQYDCskBDk6oPoPMmAq60ehzNt4MDzX+q6qRDXTMDL3Ytmn8S5AWjeUxF uD4Wb0P8pFA8n3kZOteg/WWHCUArYn2zLZlZ02pMiktZ+Ap1hvMBq/kvifSdotX3xi2k 3KDg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=P9eTbcb0c0QW79w2Lle4OK4fGAGlUg7CvrsEtlqMhrk=; fh=E72lwripL0be25y9/59kemW4sjcrLbPHabNLkPQsXIE=; b=B7IWrRgHCD7UKRJMztJiOgF8aKav2nuAbU4uAHfsrLP5DtOjl7M6f0E6nE9aXZAT6x qabXmaN6AynOvfaYvqnk6S257RCucGl1W9nb4b0nP+jqeRJFlxzxH3sNDdQocVmeJUeo 207Uax8xKmP7/CXDz4L7uIPbpK0rTvW9tlT2rvVd+tgBjdesTH+eTattVvzqY/rkucmw 8YTZYSGWRPrQA0UbXymTTnpdOHpgRBNB7y28VhcGLv9OlIfqLjAig8Z+xkKDwJnHLXyR yqWXQvHHzOvJtlA7auK/DoNevMExe1gKA9QfCcW3BCvZ7H1oadczHOq3xNc6hZUTEXcW 0TuA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=squashfs.org.uk); spf=pass (google.com: domain of linux-kernel+bounces-137619-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137619-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g5-20020ac87f45000000b00432c273f671si10967497qtk.656.2024.04.09.13.47.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 13:47:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-137619-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=squashfs.org.uk); spf=pass (google.com: domain of linux-kernel+bounces-137619-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137619-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 9E9191C20B4B for ; Tue, 9 Apr 2024 20:47:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 118E715885A; Tue, 9 Apr 2024 20:47:01 +0000 (UTC) Received: from sxb1plsmtpa01-01.prod.sxb1.secureserver.net (sxb1plsmtpa01-01.prod.sxb1.secureserver.net [188.121.53.2]) (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 83BCD2905 for ; Tue, 9 Apr 2024 20:46:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=188.121.53.2 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712695620; cv=none; b=Q13rE6PYqCsCXaPPZA/+JPtqeH94mpPiGzlge1eQ0/sB/p1m0kVEHq9YA5gXkoMwlPvMBK64rh7HcvSRWtpJNbubTr/d/wcsuZTxbeuv6Ij4xJR3lYc3MihR71DEYfN7f0GQrvM0tAoBUtNcRKYdMqVqIX/+4Kgkc72sE1lkeHI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712695620; c=relaxed/simple; bh=QTM+LP0YD0A7dbv3jscQrPsB8DT7gPc3um5gzm+C+tI=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=p8xr7AZ2ZHZecOU1gUdp82ENhUIOoVxiePUWSDvR2i7fvx2H5/35RFX4ZnE+vbus+UD1034LtQzQaGu5mxGSYIyieAJF0B2IfA3jXJc7HTDn6elSrJQcSiDC74DZc2E7xOSd0LYBHmlyHH5zmAcWPsucA3sgyhKZ4RJpNFie30s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=squashfs.org.uk; spf=pass smtp.mailfrom=squashfs.org.uk; arc=none smtp.client-ip=188.121.53.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=squashfs.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=squashfs.org.uk Received: from phoenix.fritz.box ([82.69.79.175]) by :SMTPAUTH: with ESMTPA id uIMXrvVZ9defduIMirCrSi; Tue, 09 Apr 2024 13:46:49 -0700 X-CMAE-Analysis: v=2.4 cv=GuaJ+V1C c=1 sm=1 tr=0 ts=6615a939 a=84ok6UeoqCVsigPHarzEiQ==:117 a=84ok6UeoqCVsigPHarzEiQ==:17 a=XJTnSpgKjpJfBdNX:21 a=1T6qrdwwAAAA:8 a=VwQbUJbxAAAA:8 a=FXvPX3liAAAA:8 a=OU3_bkaUkIPW1OEudewA:9 a=pdM9UVT-CToajMN3hxJJ:22 a=AjGcO6oz07-iQ99wixmX:22 a=UObqyxdv-6Yh2QiB9mM_:22 X-SECURESERVER-ACCT: phillip@squashfs.org.uk From: Phillip Lougher To: akpm@linux-foundation.org, linux-kernel@vger.kernel.org Cc: Phillip Lougher , "Ubisectech Sirius" Subject: [PATCH V2] Squashfs: check the inode number is not the invalid value of zero Date: Tue, 9 Apr 2024 21:47:23 +0100 Message-Id: <20240409204723.446925-1-phillip@squashfs.org.uk> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CMAE-Envelope: MS4xfL/wfjlBWDoeFH1N6AfOORQApCtH1tdsbN+46ujuZyxFfgxQ1pKDNuV9an83pXR24MCs0k4vZl6AeSdj/UQ9GIv8fb2nfc+rB1YO58nBcd2pX/0ILyBw wKom7pWc72NgjOKBHB49bYI8m6N4ZyRhk6IQKiAbySP06hTGkceA2D0qyKF9uGFWNl/Bt602NJNsbpEy78AjZTkeeqym4BXrVFQHH4JqbnRb5s3hDYNcSMSR /1esuSxj6FTtikF5dc2vfn0o7aY4FLhAVjSKfyYw/6SK/5GenX/OdRagm50twvZRpbzVwvZb5oFjSThat45jww== Syskiller has produced an out of bounds access in fill_meta_index(). That out of bounds access is ultimately caused because the inode has an inode number with the invalid value of zero, which was not checked. The reason this causes the out of bounds access is due to following sequence of events: 1. Fill_meta_index() is called to allocate (via empty_meta_index()) and fill a metadata index. It however suffers a data read error and aborts, invalidating the newly returned empty metadata index. It does this by setting the inode number of the index to zero, which means unused (zero is not a valid inode number). 2. When fill_meta_index() is subsequently called again on another read operation, locate_meta_index() returns the previous index because it matches the inode number of 0. Because this index has been returned it is expected to have been filled, and because it hasn't been, an out of bounds access is performed. This patch adds a sanity check which checks that the inode number is not zero when the inode is created and returns -EINVAL if it is. Reported-by: "Ubisectech Sirius" Closes: https://lore.kernel.org/lkml/87f5c007-b8a5-41ae-8b57-431e924c5915.bugreport@ubisectech.com/ Signed-off-by: Phillip Lougher -- V2: add space between "if" and "(". Move Closes: to after Reported-by:. --- fs/squashfs/inode.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/squashfs/inode.c b/fs/squashfs/inode.c index aa3411354e66..16bd693d0b3a 100644 --- a/fs/squashfs/inode.c +++ b/fs/squashfs/inode.c @@ -48,6 +48,10 @@ static int squashfs_new_inode(struct super_block *sb, struct inode *inode, gid_t i_gid; int err; + inode->i_ino = le32_to_cpu(sqsh_ino->inode_number); + if (inode->i_ino == 0) + return -EINVAL; + err = squashfs_get_id(sb, le16_to_cpu(sqsh_ino->uid), &i_uid); if (err) return err; @@ -58,7 +62,6 @@ static int squashfs_new_inode(struct super_block *sb, struct inode *inode, i_uid_write(inode, i_uid); i_gid_write(inode, i_gid); - inode->i_ino = le32_to_cpu(sqsh_ino->inode_number); inode_set_mtime(inode, le32_to_cpu(sqsh_ino->mtime), 0); inode_set_atime(inode, inode_get_mtime_sec(inode), 0); inode_set_ctime(inode, inode_get_mtime_sec(inode), 0); -- 2.39.2