mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: James Bottomley <James.Bottomley@HansenPartnership.com>
To: "\"Kai Mäkisara (Kolumbus)\"" <kai.makisara@kolumbus.fi>,
	"Samuel Moelius" <sam.moelius@trailofbits.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>,
	"open list:SCSI SUBSYSTEM" <linux-scsi@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] scsi: scsi_debug: fix one-partition tape setup bounds
Date: Thu, 04 Jun 2026 15:29:53 -0400	[thread overview]
Message-ID: <c56802d9d3f05635c5b126687d0351a647801a77.camel@HansenPartnership.com> (raw)
In-Reply-To: <4A3BD9E5-21E2-40F7-9242-71589477F2EF@kolumbus.fi>

On Thu, 2026-06-04 at 22:14 +0300, Kai Mäkisara (Kolumbus) wrote:
> 
> > On 4. Jun 2026, at 21.33, Samuel Moelius
> > <sam.moelius@trailofbits.com> wrote:
> > 
> > On Thu, Jun 4, 2026 at 9:38 AM James Bottomley
> > <James.Bottomley@hansenpartnership.com> wrote:
> > > 
> > > On Wed, 2026-06-03 at 23:55 +0000, Samuel Moelius wrote:
> > > > The tape setup path writes partition metadata one element past
> > > > the
> > > > allocated tape_blocks array when a one-partition configuration
> > > > is
> > > > selected.
> > > > 
> > > > That corrupts adjacent state during device initialization
> > > > before any
> > > > command is issued.
> > > 
> > > I still don't get what the actual problem is.  For a single
> > > partition
> > > tape I can't see where scsi_debug would actually do anything with
> > > tape_blocks[1].  What is it that you're seeing when using
> > > scsi_debug
> > > that motivates this?
> > 
> > The bug is a kernel OOB write. I can share a PoC if desired. The
> > PoC
> > sends this SCSI command through /dev/sgN:
> > 
> > ...
> 
> > Then the bug: it initializes partition 1 even though there is only
> > one
> > partition:
> > 
> >    devip->tape_eop[1] = part_1_size;
> >    devip->tape_blocks[1] = devip->tape_blocks[0] +
> >                            devip->tape_eop[0];
> >    devip->tape_blocks[1]->fl_size = TAPE_BLOCK_EOD_FLAG;
> > 
> > Because devip->tape_eop[0] == 10000, this computes:
> > 
> >    devip->tape_blocks[1] = devip->tape_blocks[0] + 10000
> > 
> > But the allocation has only 10000 elements. So this write is one
> > element past the allocation.
> 
> OK. The bug is not initialization of the pointer but writing the
> fl_size using the pointer. Good catch!

Isn't the fix actually to allocate an extra block for the EOF:

@@ -6648,7 +6648,7 @@ static int scsi_debug_sdev_configure(struct scsi_device *sdp,
        if (sdebug_ptype == TYPE_TAPE) {
                if (!devip->tape_blocks[0]) {
                        devip->tape_blocks[0] =
-                               kzalloc_objs(struct tape_block, TAPE_UNITS);
+                               kzalloc_objs(struct tape_block, TAPE_UNITS + 1);
                        if (!devip->tape_blocks[0])
                                return 1;

?

Regards,

James


  reply	other threads:[~2026-06-04 19:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-03 23:55 Samuel Moelius
2026-06-04 13:38 ` James Bottomley
2026-06-04 14:52   ` "Kai Mäkisara (Kolumbus)"
2026-06-04 16:16     ` "Kai Mäkisara (Kolumbus)"
2026-06-04 18:33   ` Samuel Moelius
2026-06-04 19:14     ` "Kai Mäkisara (Kolumbus)"
2026-06-04 19:29       ` James Bottomley [this message]
2026-06-04 19:41         ` "Kai Mäkisara (Kolumbus)"
2026-06-04 23:47         ` Samuel Moelius

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=c56802d9d3f05635c5b126687d0351a647801a77.camel@HansenPartnership.com \
    --to=james.bottomley@hansenpartnership.com \
    --cc=kai.makisara@kolumbus.fi \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=sam.moelius@trailofbits.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

all inboxes | Powered by JetHome®