Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp994411lqt; Fri, 7 Jun 2024 05:18:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVuYx2BK5zJ+x0zMFEIGXVXfO+pD2ynfjMpEc0dgzcjIw4tURRQRVqawwDflskEuPmzx5UO5+8kL4uKE5+lMWtFpyHacrmp4uqxOq+v/Q== X-Google-Smtp-Source: AGHT+IHWPTG3QUKADaTm6LGo8H63Msh0O4Vp6uvfBJjNDby+cIkWgLApQHUzUWmaE/tJnuBo2fIM X-Received: by 2002:a17:906:344e:b0:a67:8fc4:7ad1 with SMTP id a640c23a62f3a-a6cdb9dc96dmr157652566b.63.1717762696440; Fri, 07 Jun 2024 05:18:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717762696; cv=pass; d=google.com; s=arc-20160816; b=E9dt0SsnPhPRKvFyJlXHvFBxm40sUMYMRD0dk6pCTvHCI2k0oj5dXylhoUAVHAjeNp 6SIUDGCRD65VkpaRJvkMbMgAOFmcuZMjt984/Kpn/HMv+hCibVv90iZ5yZishFjrT6AX VvYsqqmlHv1vt8pBZ2hoLfYjqsz3Cm2YVk+It+XGSCVptE1eJkP4hPA59XUelyjE5mGI IM8+ZeAuAQZZJVm0YhuGQ/YiwHYldGRGDM5OkoGGsQqnKUqAnTF8EvMDlRevQj+jcIPX Eugnn5qpypsyhbDolZm90kq0BJgVwVXxsh5UkFasu+XWFMfbVa4IMVbBY1PYJbEJTsrH 2L+g== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=rZ+FvsoFzB6Ze1li1a6xt3L+qbetk7U6W84312JB2LY=; fh=nkUMnAYf6juCSH8Iv3FOCCx6z2Q6l+Gq9COqNugaNuI=; b=QHxAczmodd6byZ2hefXBgma/dvd4LEsAvwWYsMjWyxzn/V0Dn3qb3BpA53lFDYAlcv nKrREgu28+mjV0Dm0d84KgxF21xX4BRaTT5S6SMKo7+5zoknvjNgLYxFS+8TsSMG6VJr aPIe1NdlEmFbDvtrjo4BElUAIpb7sjOpYg7LPso1Bud4Y5PiL5cjmsomiOAg9qPRyzXk L3ELQ3PjOszbWxa6In7fWbAFGMA5F3Idjrjl4MaoTrLqTPcKAoohm1ygPxMRI+CLnzLP /TxnimDjUMjBLysmAlOHVJVdjAfHHck6r0WbVA4I5r1t6yyD1TIXw16f+nKTnuiI998x tzTA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=lOCRlfbe; arc=pass (i=1 spf=pass spfdomain=paragon-software.com dkim=pass dkdomain=paragon-software.com dmarc=pass fromdomain=paragon-software.com); spf=pass (google.com: domain of linux-kernel+bounces-206000-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206000-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a6c807085easi176248466b.635.2024.06.07.05.18.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 05:18:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-206000-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=lOCRlfbe; arc=pass (i=1 spf=pass spfdomain=paragon-software.com dkim=pass dkdomain=paragon-software.com dmarc=pass fromdomain=paragon-software.com); spf=pass (google.com: domain of linux-kernel+bounces-206000-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206000-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id F1B431F212E1 for ; Fri, 7 Jun 2024 12:18:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F31F4194C9D; Fri, 7 Jun 2024 12:16:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b="lOCRlfbe" 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 A67C6194A75; Fri, 7 Jun 2024 12:16:21 +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=1717762583; cv=none; b=Nq8ao1jVBy8yALTlh0pzMcXl1VkxPomtKdrDlct9V1NgvPsnaU05HIawQKA/v0QD6qgnaBV+3EvRomlbuX0arQGCd0sSo5c2Ju8ObGJS3fzFFnOdb4SX6NPtfh4FJf+EOScyqHhFN3oR1pQYITIKrDHqjdT6PvjkBlhVL8pPipE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717762583; c=relaxed/simple; bh=kH+wsSdgaNX52+l+RYxhfvSSu0fwEe5uQnP97NGPDIs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DwZy3N3hMTpnOn37g+q7H3oeoUkywVOFCjsiyAAgnKuI8hX7a005Jub9EdnPCPpuwyGPXYuVkzmRl6//Hbv+5NIMphGlbPDKDGU9AqDvcJS3huEmS4BjUgCazOShkmnCmsaB0eABorPQRWfYnuVCwPGi9rI32F4Z3qsLgtOBGEc= 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=lOCRlfbe; 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 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 035942111; Fri, 7 Jun 2024 12:08:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1717762106; bh=rZ+FvsoFzB6Ze1li1a6xt3L+qbetk7U6W84312JB2LY=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=lOCRlfbe8SKKecox0mm04M6lzDP9XrKOTvottIWpmgvqdPiIKgjXFSA5O3suYHubH rVfryGrXjyJjkUb3qWoNmGFBQIhz9cSH4qOhfaU0Ll2zudT4mNNuetU8jRy77Anm6T 1auh4x8qin3If9Joy6mPN25ZqsChJZhGWjmd8z3A= Received: from ntfs3vm.paragon-software.com (192.168.211.95) 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; Fri, 7 Jun 2024 15:16:19 +0300 From: Konstantin Komarov To: CC: , , Konstantin Komarov , lei lu Subject: [PATCH 12/18] fs/ntfs3: Add a check for attr_names and oatbl Date: Fri, 7 Jun 2024 15:15:42 +0300 Message-ID: <20240607121548.18818-13-almaz.alexandrovich@paragon-software.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240607121548.18818-1-almaz.alexandrovich@paragon-software.com> References: <20240607121548.18818-1-almaz.alexandrovich@paragon-software.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) Added out-of-bound checking for *ane (ATTR_NAME_ENTRY). Reported-by: lei lu Fixes: 865e7a7700d93 ("fs/ntfs3: Reduce stack usage") Signed-off-by: Konstantin Komarov --- fs/ntfs3/fslog.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/fs/ntfs3/fslog.c b/fs/ntfs3/fslog.c index d7807d255dfe..055c2af602c3 100644 --- a/fs/ntfs3/fslog.c +++ b/fs/ntfs3/fslog.c @@ -3722,6 +3722,8 @@ int log_replay(struct ntfs_inode *ni, bool *initialized) u64 rec_lsn, checkpt_lsn = 0, rlsn = 0; struct ATTR_NAME_ENTRY *attr_names = NULL; + u32 attr_names_bytes = 0; + u32 oatbl_bytes = 0; struct RESTART_TABLE *dptbl = NULL; struct RESTART_TABLE *trtbl = NULL; const struct RESTART_TABLE *rt; @@ -3736,6 +3738,7 @@ int log_replay(struct ntfs_inode *ni, bool *initialized) struct NTFS_RESTART *rst = NULL; struct lcb *lcb = NULL; struct OPEN_ATTR_ENRTY *oe; + struct ATTR_NAME_ENTRY *ane; struct TRANSACTION_ENTRY *tr; struct DIR_PAGE_ENTRY *dp; u32 i, bytes_per_attr_entry; @@ -4314,17 +4317,40 @@ int log_replay(struct ntfs_inode *ni, bool *initialized) lcb = NULL; check_attribute_names2: - if (rst->attr_names_len && oatbl) { - struct ATTR_NAME_ENTRY *ane = attr_names; - while (ane->off) { + if (attr_names && oatbl) { + off = 0; + for (;;) { + /* Check we can use attribute name entry 'ane'. */ + static_assert(sizeof(*ane) == 4); + if (off + sizeof(*ane) > attr_names_bytes) { + /* just ignore the rest. */ + break; + } + + ane = Add2Ptr(attr_names, off); + t16 = le16_to_cpu(ane->off); + if (!t16) { + /* this is the only valid exit. */ + break; + } + + /* Check we can use open attribute entry 'oe'. */ + if (t16 + sizeof(*oe) > oatbl_bytes) { + /* just ignore the rest. */ + break; + } + /* TODO: Clear table on exit! */ - oe = Add2Ptr(oatbl, le16_to_cpu(ane->off)); + oe = Add2Ptr(oatbl, t16); t16 = le16_to_cpu(ane->name_bytes); + off += t16 + sizeof(*ane); + if (off > attr_names_bytes) { + /* just ignore the rest. */ + break; + } oe->name_len = t16 / sizeof(short); oe->ptr = ane->name; oe->is_attr_name = 2; - ane = Add2Ptr(ane, - sizeof(struct ATTR_NAME_ENTRY) + t16); } } -- 2.34.1