public inbox for ntfs3@lists.linux.dev
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: almaz.alexandrovich@paragon-software.com
Cc: ntfs3@lists.linux.dev
Subject: [bug report] fs/ntfs3: inconsistent NULL checking in attr_allocate_frame()
Date: Tue, 24 Aug 2021 14:40:57 +0300	[thread overview]
Message-ID: <20210824114057.GE31143@kili> (raw)

Hello Konstantin Komarov,

This is a semi-automatic email about new static checker warnings.

The patch be71b5cba2e6: "fs/ntfs3: Add attrib operations" from Aug 
13, 2021, leads to the following Smatch complaint:

    fs/ntfs3/attrib.c:1678 attr_allocate_frame()
    error: we previously assumed 'attr_b' could be null (see line 1591)

fs/ntfs3/attrib.c
  1582                  /* add new segment [next_svcn : evcn1 - next_svcn )*/
  1583                  if (!ni->attr_list.size) {
  1584                          err = ni_create_attr_list(ni);
  1585                          if (err)
  1586                                  goto out;
  1587                          /* layout of records is changed */
  1588                          le_b = NULL;
  1589                          attr_b = ni_find_attr(ni, NULL, &le_b, ATTR_DATA, NULL,
  1590						      0, NULL, &mi_b);
  1591				if (!attr_b) {
                                     ^^^^^^
Check for NULL

  1592					err = -ENOENT;
  1593					goto out;
  1594				}
  1595	
  1596				attr = attr_b;
  1597				le = le_b;
  1598				mi = mi_b;
  1599				goto repack;
  1600			}
  1601		}
  1602	
  1603		svcn = evcn1;
  1604	
  1605		/* Estimate next attribute */
  1606		attr = ni_find_attr(ni, attr, &le, ATTR_DATA, NULL, 0, &svcn, &mi);
  1607	
  1608		if (attr) {
  1609			CLST alloc = bytes_to_cluster(
  1610				sbi, le64_to_cpu(attr_b->nres.alloc_size));
  1611			CLST evcn = le64_to_cpu(attr->nres.evcn);
  1612	
  1613			if (end < next_svcn)
  1614				end = next_svcn;
  1615			while (end > evcn) {
  1616				/* remove segment [svcn : evcn)*/
  1617				mi_remove_attr(mi, attr);
  1618	
  1619				if (!al_remove_le(ni, le)) {
  1620					err = -EINVAL;
  1621					goto out;
  1622				}
  1623	
  1624				if (evcn + 1 >= alloc) {
  1625					/* last attribute segment */
  1626					evcn1 = evcn + 1;
  1627					goto ins_ext;
  1628				}
  1629	
  1630				if (ni_load_mi(ni, le, &mi)) {
  1631					attr = NULL;
  1632					goto out;
  1633				}
  1634	
  1635				attr = mi_find_attr(mi, NULL, ATTR_DATA, NULL, 0,
  1636						    &le->id);
  1637				if (!attr) {
  1638					err = -EINVAL;
  1639					goto out;
  1640				}
  1641				svcn = le64_to_cpu(attr->nres.svcn);
  1642				evcn = le64_to_cpu(attr->nres.evcn);
  1643			}
  1644	
  1645			if (end < svcn)
  1646				end = svcn;
  1647	
  1648			err = attr_load_runs(attr, ni, run, &end);
  1649			if (err)
  1650				goto out;
  1651	
  1652			evcn1 = evcn + 1;
  1653			attr->nres.svcn = cpu_to_le64(next_svcn);
  1654			err = mi_pack_runs(mi, attr, run, evcn1 - next_svcn);
  1655			if (err)
  1656				goto out;
  1657	
  1658			le->vcn = cpu_to_le64(next_svcn);
  1659			ni->attr_list.dirty = true;
  1660			mi->dirty = true;
  1661	
  1662			next_svcn = le64_to_cpu(attr->nres.evcn) + 1;
  1663		}
  1664	ins_ext:
  1665		if (evcn1 > next_svcn) {
  1666			err = ni_insert_nonresident(ni, ATTR_DATA, NULL, 0, run,
  1667						    next_svcn, evcn1 - next_svcn,
  1668						    attr_b->flags, &attr, &mi);
  1669			if (err)
  1670				goto out;
  1671		}
  1672	ok:
  1673		run_truncate_around(run, vcn);
  1674	out:
  1675		if (new_valid > data_size)
  1676			new_valid = data_size;
  1677	
  1678		valid_size = le64_to_cpu(attr_b->nres.valid_size);
                                         ^^^^^^^^^^^^^^^^^^^^^^^
Unchecked dereference

  1679		if (new_valid != valid_size) {
  1680			attr_b->nres.valid_size = cpu_to_le64(valid_size);

regards,
dan carpenter

                 reply	other threads:[~2021-08-24 11:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210824114057.GE31143@kili \
    --to=dan.carpenter@oracle.com \
    --cc=almaz.alexandrovich@paragon-software.com \
    --cc=ntfs3@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox