linux-hardening.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bob Copeland <me@bobcopeland.com>
To: Kees Cook <keescook@chromium.org>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>,
	linux-karma-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH][next] fs: omfs: Use flexible-array member in struct omfs_extent
Date: Wed, 19 Jul 2023 09:03:29 -0400	[thread overview]
Message-ID: <ZLffIfEKz/nR9Jj/@bobcopeland.com> (raw)
In-Reply-To: <202307170758.14B5D83D@keescook>

On Mon, Jul 17, 2023 at 08:20:22AM -0700, Kees Cook wrote:
> > @@ -14,7 +14,7 @@ static u32 omfs_max_extents(struct omfs_sb_info *sbi, int offset)
> >  {
> >  	return (sbi->s_sys_blocksize - offset -
> >  		sizeof(struct omfs_extent)) /
> > -		sizeof(struct omfs_extent_entry) + 1;
> > +		sizeof(struct omfs_extent_entry);
> >  }
> 
> I think the original calculation meant to do:
> 
>   	return (sbi->s_sys_blocksize - offset -
>   		(sizeof(struct omfs_extent) - sizeof(struct omfs_extent_entry))) /
> 		sizeof(struct omfs_extent_entry);

I can confirm the intent.  I also went back and looked at the usages just
to be sure.

In this case, there are two possible values for x = s_sys_blocksize - offset:
7728 or 8128, and both can be divided by 16 evenly so you have either:

    f_old = (x - 32) / 16 + 1 or:
    f_new = (x - 16) / 16

they both simplify to x/16 - 1 so they are equivalent for these inputs.

-- 
Bob Copeland %% https://bobcopeland.com/

      reply	other threads:[~2023-07-19 13:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-14 19:56 [PATCH][next] fs: omfs: Use flexible-array member in struct omfs_extent Gustavo A. R. Silva
2023-07-17 15:20 ` Kees Cook
2023-07-19 13:03   ` Bob Copeland [this message]

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=ZLffIfEKz/nR9Jj/@bobcopeland.com \
    --to=me@bobcopeland.com \
    --cc=gustavoars@kernel.org \
    --cc=keescook@chromium.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-karma-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    /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).