Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp514930rwe; Fri, 26 Aug 2022 09:04:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR74lKcyfVjZjD0ASdpq5ae/0V+lktQMpceibeZfJigKJp0ZyDbCeW3QgtyRxaRLqZN1Clcc X-Received: by 2002:a17:902:bcc9:b0:16e:fde3:172f with SMTP id o9-20020a170902bcc900b0016efde3172fmr4491885pls.36.1661529860754; Fri, 26 Aug 2022 09:04:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661529860; cv=none; d=google.com; s=arc-20160816; b=TEaBBgfLsfBKS6U47qpVu6Mlp6gzY/OVl9TYGiLtSuJuHlwufuif5EAtj5WoNbxUWm lMwdWqxBNmHq8Ii8T7milEzYTYDMwvLv9ncI5AH15qg60BlYPdcDNywBz/iA6pypR+m8 +ByRejmv9rVVv816WeRQmIuCHqWdPZBGddPHQX2AMDGL7/ShBYI2tF/aRT1zulDGoFSi D+YLyKAGeAx9s1gY3724OM8oO16RpFCF/YPkoO0Aq+3a1FGZL6jy3PUXhgPTAB2+icyu mOEwgrXitl6NNrpC1ZNP12QLsoedL2mSUc/LCUAfwSAkuFRp1j/RNyDQOsIr8amX3bEh uv/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9Xr0k1F/n6DXUYyny/jSc9xyKQVr9bMMBjQ0x9hJugc=; b=gXTvw2r0bFRSYLovMeSt0xCNh9oM1bLBFgidNJIWAqFxFFtlVrgzRGEsxx8kzp70wN W15EF+/m3LcIs1JDxtXQbaO21Xy7i0w4pEUiEqY4aykHWYsq8G820voP+BeeLh2kSbMp klgeRSiy1ALJdxfaCw2+hKUyqkt5gFcV018MlT9Zkx1YBCd5MQ2yCFKRV41lNyO2WJ8b 44YfuISVPr7tzC/OQz808roU6rImR3U6iNM+I9a9+tgCO47Hfee1HnpDjO59yQJCS4dz U6xRBo9GBk+8W4J05reOz6zF3eQUlsgpqwmPWjZtpQZHrqu2VWo83ZMSZ1HwrY0jp3Qq VNZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=EFek5s+7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o29-20020a63731d000000b00429f677c808si2265873pgc.518.2022.08.26.09.04.09; Fri, 26 Aug 2022 09:04:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=EFek5s+7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344678AbiHZPt7 (ORCPT + 99 others); Fri, 26 Aug 2022 11:49:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344746AbiHZPt2 (ORCPT ); Fri, 26 Aug 2022 11:49:28 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A03FC6E96 for ; Fri, 26 Aug 2022 08:49:20 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id io24so1925131plb.1 for ; Fri, 26 Aug 2022 08:49:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=9Xr0k1F/n6DXUYyny/jSc9xyKQVr9bMMBjQ0x9hJugc=; b=EFek5s+75roAZuIl4BSgg8kXDr1+N1he6wQ9DGg6l6S91/oI41FAUIF1zAinsrbmEu QPE743pmSEttSnsgEY7SIvXx+NG59pxAfXWRmKW/vDRqcfiv4M+JSKkDRQZP50ynbPIs YuxCzxvqjk62RMWy7fSbDXP9JbxIU/v2XBmWOcyooYH+kCjF1xZgNytPj0TSEktMQkjQ 3cAGIVmPZCQEzIBJ+2SVB8LeXK3IAwGiSJB5HNjNe7qKmcD1vAsklEO5RdrfgnE7hn2F cDeCGF++9Z1E55kAUk4Ub8jtVBAcazTYnzHCP8C65q5chM0dzRzXKmqyVuoCuDlhMDGl RjSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=9Xr0k1F/n6DXUYyny/jSc9xyKQVr9bMMBjQ0x9hJugc=; b=mMdUGDMXC36xJfhMLJ0dpXvbGQtBpGWHNcMAskRDOcZdHFrAXdFBhWIBEmXa7E71em fvyidhdSez/Mae15GAddBYf+3b739er8LnlHSQzS9CGRUYBoD2RzCt1hk591eOPw9Rm6 mL3QyEdAADDdWMUcV6abP0T1oePt7kpauzXs84LMtiK1yxXTxUkuWiZcZrvgSrbiKnnL 6sYZH9GCPAMwObO19zKL3UuqHydP/sK+3LOHxBgwK/C7T2fiY+4ww9ZmPDMgK2Rcyutw lPKEf3ELmBo+BQwFvKh77lkos3ebPWezLr8G/Hry5suRBGpsTxFUKijpv6+KMomtOPpt 5ZNg== X-Gm-Message-State: ACgBeo39onamS7TDjY7KAiPm27oDTy6uXoZmYZaN3h0vfZCui3Ambl5h j7RlEfHXaTR/AcljhzLanuA= X-Received: by 2002:a17:90b:4a0e:b0:1fb:4c5e:9584 with SMTP id kk14-20020a17090b4a0e00b001fb4c5e9584mr5137723pjb.152.1661528959477; Fri, 26 Aug 2022 08:49:19 -0700 (PDT) Received: from localhost ([36.112.195.70]) by smtp.gmail.com with ESMTPSA id e11-20020a170902784b00b00173164792aasm1741388pln.127.2022.08.26.08.49.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Aug 2022 08:49:19 -0700 (PDT) From: Hawkins Jiawei To: dan.carpenter@oracle.com Cc: akpm@linux-foundation.org, anton@tuxera.com, chenxiaosong2@huawei.com, linux-kernel@vger.kernel.org, linux-ntfs-dev@lists.sourceforge.net, syzbot+5f8dcabe4a3b2c51c607@syzkaller.appspotmail.com, syzkaller-bugs@googlegroups.com, yin31149@gmail.com Subject: Re: [PATCH] ntfs: change check order in ntfs_attr_find Date: Fri, 26 Aug 2022 23:42:32 +0800 Message-Id: <20220826154231.6634-1-yin31149@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220826151520.GF2071@kadam> References: <20220826151520.GF2071@kadam> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 26 Aug 2022 at 23:15, Dan Carpenter wrote: > > On Fri, Aug 26, 2022 at 08:32:57PM +0800, Hawkins Jiawei wrote: > > > syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master > > > > > > Looks like it is improper check order that causes this bug. > > > > Sorry for wrong command. > > #syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master > > > > diff --git a/fs/ntfs/attrib.c b/fs/ntfs/attrib.c > > index 52615e6090e1..6480cd2d371d 100644 > > --- a/fs/ntfs/attrib.c > > +++ b/fs/ntfs/attrib.c > > @@ -594,10 +594,11 @@ static int ntfs_attr_find(const ATTR_TYPE type, const ntfschar *name, > >       for (;; a = (ATTR_RECORD*)((u8*)a + le32_to_cpu(a->length))) { > >               u8 *mrec_end = (u8 *)ctx->mrec + > >                              le32_to_cpu(ctx->mrec->bytes_allocated); > > +             if ((u8*)a < (u8*)ctx->mrec || (u8*)a > mrec_end) > > +                     break; > > This definitely seems like a bug.  But your code won't build.  Syzbot > must have -Werror turned off? Hi Dan, Did you mean we should put the variable declares at the beginning of the function? (Correct me if I understand anything wrong) > > Btw, this was in the original code, but those casts are ugly.  Ideally > there would be some way to get rid of them.  But otherwise at least > put a space after the u8.  "(u8 *)a < (u8 *)ctx->mrec". > > >               u8 *name_end = (u8 *)a + le16_to_cpu(a->name_offset) + > >                              a->name_length * sizeof(ntfschar); > > -             if ((u8*)a < (u8*)ctx->mrec || (u8*)a > mrec_end || > > -                 name_end > mrec_end) > > +             if (name_end > mrec_end) > >                       break; > > regards, > dan carpenter So maybe I can try to refactor these codes. But I wonder if this can be done in a seperate bug