public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: mwilck@suse.com
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>,
	"Christoph Hellwig" <hch@lst.de>,
	linux-scsi@vger.kernel.org, target-devel@vger.kernel.org,
	"David Disseldorp" <ddiss@suse.com>,
	"Jürgen Groß" <jgross@suse.com>,
	"Chaitanya Kulkarni" <Chaitanya.Kulkarni@wdc.com>
Subject: Re: [PATCH v2 1/2] target: pscsi: avoid OOM in pscsi_map_sg()
Date: Wed, 24 Mar 2021 08:14:12 +0100	[thread overview]
Message-ID: <20210324071412.GC647@lst.de> (raw)
In-Reply-To: <20210323212431.15306-1-mwilck@suse.com>

On Tue, Mar 23, 2021 at 10:24:30PM +0100, mwilck@suse.com wrote:
> From: Martin Wilck <mwilck@suse.com>
> 
> pscsi_map_sg() uses the variable nr_pages as a hint for bio_kmalloc()
> how many vector elements to allocate. If nr_pages is < BIO_MAX_PAGES,
> it will be reset to 0 after successful allocation of the bio.
> 
> If bio_add_pc_page() fails later for whatever reason, pscsi_map_sg()
> tries to allocate another bio, passing nr_vecs=0. This causes
> bio_add_pc_page() to fail immediately in the next call. pci_map_sg()
> continues to allocate zero-length bios until memory is exhausted and
> the kernel crashes with OOM. This can be easily observed by exporting
> a SATA DVD drive via pscsi. The target crashes as soon as the client
> tries to access the DVD LUN. In the case I analyzed, bio_add_pc_page()
> would fail because the DVD device's max_sectors_kb (128) was
> exceeded.
> 
> Avoid this by simply not resetting nr_pages to 0 after allocating the
> bio. This way, the client receives an IO error when it tries to send
> requests exceeding the devices max_sectors_kb, and eventually gets
> it right. The client must still limit max_sectors_kb e.g. by an udev
> rule if (like in my case) the driver doesn't report valid block
> limits, otherwise it encounters I/O errors.
> 
> Signed-off-by: Martin Wilck <mwilck@suse.com>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

  parent reply	other threads:[~2021-03-24  7:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-23 21:24 [PATCH v2 1/2] target: pscsi: avoid OOM in pscsi_map_sg() mwilck
2021-03-23 21:24 ` [PATCH v2 2/2] target: pscsi: cleanup after failure " mwilck
2021-03-24  7:14   ` Christoph Hellwig
2021-03-24 17:24   ` Lee Duncan
2021-03-24  7:14 ` Christoph Hellwig [this message]
2021-03-24 17:24 ` [PATCH v2 1/2] target: pscsi: avoid OOM " Lee Duncan
2021-03-25  3:53 ` Martin K. Petersen

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=20210324071412.GC647@lst.de \
    --to=hch@lst.de \
    --cc=Chaitanya.Kulkarni@wdc.com \
    --cc=ddiss@suse.com \
    --cc=jgross@suse.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=mwilck@suse.com \
    --cc=target-devel@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