linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Al Viro <viro@zeniv.linux.org.uk>
To: Lizhi Xu <lizhi.xu@windriver.com>
Cc: brauner@kernel.org, jack@suse.cz, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org, phillip@squashfs.org.uk,
	squashfs-devel@lists.sourceforge.net,
	syzbot+24ac24ff58dc5b0d26b9@syzkaller.appspotmail.com,
	syzkaller-bugs@googlegroups.com
Subject: Re: [PATCH V7] squashfs: Add symlink size check in squash_read_inode
Date: Mon, 5 Aug 2024 02:40:37 +0100	[thread overview]
Message-ID: <20240805014037.GF5334@ZenIV> (raw)
In-Reply-To: <20240805010231.1197391-1-lizhi.xu@windriver.com>

On Mon, Aug 05, 2024 at 09:02:31AM +0800, Lizhi Xu wrote:
> On Sun, 4 Aug 2024 22:20:34 +0100, Al Viro wrote:
> > Alternatively, just check ->i_size after assignment.  loff_t is
> > always a 64bit signed; le32_to_cpu() returns 32bit unsigned.
> > Conversion from u32 to s64 is always going to yield a non-negative
> > result; comparison with PAGE_SIZE is all you need there.

> It is int overflow, not others. 

Excuse me, what?

> Please see my V7 patch,
> Link: https://lore.kernel.org/all/20240803074349.3599957-1-lizhi.xu@windriver.com/

I have seen your patch.  Integer overflow has nothing to do with
the problem here.

Please, show me an unsigned int value N such that

_Bool mismatch(unsigned int N)
{
	u32 v32 = N;
	loff_t v64 = N;

	return (v32 > PAGE_SIZE) != (v64 > PAGE_SIZE);
}

would yield true if passed that value as an argument.

Note that assignment of le32_to_cpu() result to inode->i_size
does conversion from unsigned 32bit integer type to a signed 64bit
integer type.  Since the range of the former fits into the range of the
latter, conversion preserves value.  In other words, possible values
of inode->i_size after such assignment are from 0 to (loff_t)0xfffffff
and (inode->i_size > PAGE_SIZE) is true in exactly the same cases when
(symlink_size > PAGE_SIZE) is true with your patch.

Again, on all architectures inode->i_size is capable of representing
all values in range 0..4G-1 (for rather obvious reasons - we want the
kernel to be able to work with files larger than 4Gb).  There is
no wraparound of any kind on that assignment.

See https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf,
in particular sections 6.5.16.1[2] and 6.3.1.3[1]

  reply	other threads:[~2024-08-05  1:40 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-31  8:12 [syzbot] [squashfs?] KMSAN: uninit-value in pick_link syzbot
2024-08-01  2:27 ` [PATCH] filemap: Init the newly allocated folio memory to 0 for the filemap Lizhi Xu
2024-08-01  2:58   ` Al Viro
2024-08-01  5:28     ` Lizhi Xu
2024-08-01  7:10       ` Al Viro
2024-08-01  7:24         ` Al Viro
2024-08-01  8:12         ` Lizhi Xu
2024-08-01  9:13           ` Lizhi Xu
2024-08-01 12:42           ` Al Viro
2024-08-01 15:17             ` [PATCH V2] squashfs: Add length check in squashfs_symlink_read_folio Lizhi Xu
2024-08-01 15:30               ` Jan Kara
2024-08-02  1:39                 ` Lizhi Xu
2024-08-02  1:50                 ` [PATCH V3] squashfs: Add i_size check in squash_read_inode Lizhi Xu
2024-08-02  3:01                   ` [PATCH V4] " Lizhi Xu
2024-08-02  9:33                     ` Jan Kara
2024-08-02 11:16                       ` [PATCH V5] " Lizhi Xu
2024-08-02 13:52                         ` Al Viro
2024-08-02 14:44                           ` [PATCH] filemap: Init the newly allocated folio memory to 0 for the filemap Lizhi Xu
2024-08-02 15:03                             ` Al Viro
2024-08-03  4:07                               ` [PATCH V6] squashfs: Add symlink size check in squash_read_inode Lizhi Xu
2024-08-03  7:43                                 ` [PATCH V7] " Lizhi Xu
2024-08-04 21:16                                   ` Phillip Lougher
2024-08-04 21:20                                     ` Al Viro
2024-08-04 22:31                                       ` Phillip Lougher
2024-08-05  7:03                                         ` Christian Brauner
2024-08-05  1:02                                       ` Lizhi Xu
2024-08-05  1:40                                         ` Al Viro [this message]
2024-08-06  2:56                                           ` Lizhi Xu
2024-08-06  4:59                                             ` Al Viro
2024-08-06  6:19                                               ` Lizhi Xu
2024-08-06  6:58                                                 ` Al Viro

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=20240805014037.GF5334@ZenIV \
    --to=viro@zeniv.linux.org.uk \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizhi.xu@windriver.com \
    --cc=phillip@squashfs.org.uk \
    --cc=squashfs-devel@lists.sourceforge.net \
    --cc=syzbot+24ac24ff58dc5b0d26b9@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    /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;
as well as URLs for NNTP newsgroup(s).