Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2854849pxb; Tue, 24 Aug 2021 09:07:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw4ozJvFGbNgAlLMMwfZuFHQJwdBPltwshdVKiwJYLpYrFDoJMQ/63yY7cwQJRdmONVsfNv X-Received: by 2002:a05:6402:3486:: with SMTP id v6mr8776727edc.21.1629821265212; Tue, 24 Aug 2021 09:07:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629821265; cv=none; d=google.com; s=arc-20160816; b=bgiqQby8K+d3wQWAEkUBfQR00xXOfPeD2E3MbIw9gnLm3ViIt62DWnrjK/nx0fa7fA o0pfOBXRO0SKN4fsJ/7o+SUtzlGE+WZIMu8fvNJPFV1g2VmGsJHRGQjP780j4ybp771T t+tiHz/ACCG2Jnkut/tWOmUqnaDA1WRhBCfbE9wDMhXgWUTMpOUfKH5/VkIT0gpnlbhl DgZHcQVY9cb9MJYA8G/xmpol6abd7ds1xzRg/g/VmFXnV2byBn0JcHE2joHoK34OKAYt P68AjdC3HhYDpvNn7CabTnEgzhucP3em7e560eY8DNxqrSze+Aha570FqvxMSvCrAvfa ukNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=poU6UxSe+vqBcMpX3p5PAXt32In/R0qv0Zl1gWkMej0=; b=CEUJ/Ff1o2lDV5KeIoSvwgwPzOXgQx20cydc+Bdh4BsG8clxUn69bmwisr58rsva8j /qeBd83tKvVYeKUnaL/FmmN876FMK6U02Uvx/A77Fqsq5B4D1UIcXECTpjE4P5XWrFoa tOnkpVCzta+zQIps7lfLBdjF7b5euMg755Z8J/OwwWJkzSsYK5M1aAlR2m5kPgrvAuIu jgQ1ZyoIsP3u2PE3TfU/pNYMYhVjzMmw+hKACD+o68RrSbd+7ozIlr9+8ws6dDO05BNh cDE7E2qDWIXq6CKfRyeEax358UyZR3Uu/y+U5oxdImXcOeGzd5Y4gICrgNkspoHJnTQh jibA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=u48N+5kK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a22si4836230eda.42.2021.08.24.09.07.16; Tue, 24 Aug 2021 09:07:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=u48N+5kK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S238474AbhHXQD4 (ORCPT + 99 others); Tue, 24 Aug 2021 12:03:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238413AbhHXQDd (ORCPT ); Tue, 24 Aug 2021 12:03:33 -0400 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1682C061757; Tue, 24 Aug 2021 09:02:48 -0700 (PDT) Received: by mail-lf1-x129.google.com with SMTP id x27so46584667lfu.5; Tue, 24 Aug 2021 09:02:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=poU6UxSe+vqBcMpX3p5PAXt32In/R0qv0Zl1gWkMej0=; b=u48N+5kK/p3O1LusihjD74avPElDU4N3bsljZPgfQZ0p0zH+fHDGLBt1RxRnIeCAaw CjqxonXgj/EL8EtOarJIBQg6Fc8xtLCWY7K6oe4pHvCbQx/Gk+Qdp+s2PUsEEijQhqaI v6EDsIyuAFHeR22fDLix8Q92iduNYMpyzNiKb+DBg8GgwQmfk3BrqPunz7Zl0RKiwSeM SZceBqvuUUWOFoJ+LHKCadWF7dRt2sdpNIiQh/y86BB8L9ADAqGgVzQZJi48nD3ANJK6 2ehmjqblhq8AAk4IWUfyCndVZMKWXLObW6tK64FCuoqZKVAik1Ll2Afk0U2Wtdac+CuQ zfPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=poU6UxSe+vqBcMpX3p5PAXt32In/R0qv0Zl1gWkMej0=; b=ksQuAgFlZcUaeK82KkmgK4eI2ppnaXj2RFBPKCp+xY3Dkeijr0W6XdnQXaCYE1mvF/ vNKkc2rOWqD24dX3eReErsBDr+o/C3oTLa6mWyZklkrMt6PxUWxW54DzwwQC76z6B7np RMCxTGE6itanVJhLhCONd1a+Q7HNCw2bL7l5dB7N+QZr+meUGPpR9mL6vSH0UONl8HmI VMQBCxRV/KBOdwgQTt8Nl8f9PQUmjBovg34cEDnOKyRUpeQW9H0Fg462APUHaQhKturA cpX19Zi7XXVORDpbq5sOsREeWmpZwfkkQxd01FTKFqyWvWEfnqHrJMUSb4oAgxCzuRzY 3uvw== X-Gm-Message-State: AOAM531dkS9tR+zHVM8xe2+TEbcmn8++WFE8yXAIdFxnY1v/7ADqGs28 4SSs1csuaJ7EqjnMeIzDRLg= X-Received: by 2002:ac2:5091:: with SMTP id f17mr28576173lfm.42.1629820966958; Tue, 24 Aug 2021 09:02:46 -0700 (PDT) Received: from kari-VirtualBox (85-23-89-224.bb.dnainternet.fi. [85.23.89.224]) by smtp.gmail.com with ESMTPSA id y5sm1238590ljd.38.2021.08.24.09.02.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 09:02:46 -0700 (PDT) Date: Tue, 24 Aug 2021 19:02:44 +0300 From: Kari Argillander To: Dan Carpenter Cc: Konstantin Komarov , ntfs3@lists.linux.dev, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [PATCH] fs/ntfs3: add checks for allocation failure Message-ID: <20210824160244.ruutwl3nq6b5feec@kari-VirtualBox> References: <20210824115236.GJ31143@kili> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210824115236.GJ31143@kili> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 24, 2021 at 02:52:36PM +0300, Dan Carpenter wrote: > Add a check for when the kzalloc() in init_rsttbl() fails. Some of > the callers checked for NULL and some did not. I went down the call > tree and added NULL checks where ever they were missing. > > Fixes: b46acd6a6a62 ("fs/ntfs3: Add NTFS journal") > Signed-off-by: Dan Carpenter Seems ok. It is not easist file to follow. log_replay is monster and it should be refactor in some point. I'm certain that many more bugs will be founded there. Also at least community does not have very good testing interface for this. Reviewed-by: Kari Argillander > --- > fs/ntfs3/fslog.c | 21 ++++++++++++++++++--- > 1 file changed, 18 insertions(+), 3 deletions(-) > > diff --git a/fs/ntfs3/fslog.c b/fs/ntfs3/fslog.c > index 397ba6a956e7..209fe6ddead0 100644 > --- a/fs/ntfs3/fslog.c > +++ b/fs/ntfs3/fslog.c > @@ -807,7 +807,11 @@ static inline struct RESTART_TABLE *init_rsttbl(u16 esize, u16 used) > u32 off; > u32 bytes = esize * used + sizeof(struct RESTART_TABLE); > u32 lf = sizeof(struct RESTART_TABLE) + (used - 1) * esize; > - struct RESTART_TABLE *t = ntfs_zalloc(bytes); > + struct RESTART_TABLE *t; > + > + t = ntfs_zalloc(bytes); > + if (!t) > + return NULL; > > t->size = cpu_to_le16(esize); > t->used = cpu_to_le16(used); > @@ -831,7 +835,11 @@ static inline struct RESTART_TABLE *extend_rsttbl(struct RESTART_TABLE *tbl, > u16 esize = le16_to_cpu(tbl->size); > __le32 osize = cpu_to_le32(bytes_per_rt(tbl)); > u32 used = le16_to_cpu(tbl->used); > - struct RESTART_TABLE *rt = init_rsttbl(esize, used + add); > + struct RESTART_TABLE *rt; > + > + rt = init_rsttbl(esize, used + add); > + if (!rt) > + return NULL; > > memcpy(rt + 1, tbl + 1, esize * used); > > @@ -864,8 +872,11 @@ static inline void *alloc_rsttbl_idx(struct RESTART_TABLE **tbl) > __le32 *e; > struct RESTART_TABLE *t = *tbl; > > - if (!t->first_free) > + if (!t->first_free) { > *tbl = t = extend_rsttbl(t, 16, ~0u); > + if (!t) > + return NULL; > + } > > off = le32_to_cpu(t->first_free); > > @@ -4482,6 +4493,10 @@ int log_replay(struct ntfs_inode *ni, bool *initialized) > } > > dp = alloc_rsttbl_idx(&dptbl); > + if (!dp) { > + err = -ENOMEM; > + goto out; > + } > dp->target_attr = cpu_to_le32(t16); > dp->transfer_len = cpu_to_le32(t32 << sbi->cluster_bits); > dp->lcns_follow = cpu_to_le32(t32); > -- > 2.20.1 > >