* Re: [Qemu-devel] [Fwd: [PATCH v4 07/21] iscsi: Handle failure for potentially large allocations] [not found] <00c425bd67fc66567dc683205f8f60f7.squirrel@ssl.dlhnet.de> @ 2014-08-22 7:40 ` Peter Lieven 2014-08-22 8:42 ` Kevin Wolf 0 siblings, 1 reply; 7+ messages in thread From: Peter Lieven @ 2014-08-22 7:40 UTC (permalink / raw) To: Kevin Wolf; +Cc: benoit.canet, Paolo Bonzini, maxa, qemu-devel, stefanha Am 22.08.2014 um 09:35 schrieb Peter Lieven: > Some code in the block layer makes potentially huge allocations. Failure > is not completely unexpected there, so avoid aborting qemu and handle > out-of-memory situations gracefully. > > This patch addresses the allocations in the iscsi block driver. > > Signed-off-by: Kevin Wolf <kwolf@redhat.com> > Acked-by: Paolo Bonzini <pbonzini@redhat.com> > Reviewed-by: Benoit Canet <benoit@irqsave.net> > Reviewed-by: Eric Blake <eblake@redhat.com> > --- > block/iscsi.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/block/iscsi.c b/block/iscsi.c > index 84aa22a..06afa78 100644 > --- a/block/iscsi.c > +++ b/block/iscsi.c > @@ -893,7 +893,10 @@ coroutine_fn iscsi_co_write_zeroes(BlockDriverState > *bs, int64_t sector_num, > nb_blocks = sector_qemu2lun(nb_sectors, iscsilun); > > if (iscsilun->zeroblock == NULL) { > - iscsilun->zeroblock = g_malloc0(iscsilun->block_size); > + iscsilun->zeroblock = g_try_malloc0(iscsilun->block_size); > + if (iscsilun->zeroblock == NULL) { > + return -ENOMEM; > + } > } > > iscsi_co_init_iscsitask(iscsilun, &iTask); Unfortunately, I missed that one. The zeroblock is typicalls 512 Byte or 4K depending on the blocksize. What is significantly larger is the allocationmap. It is typically created on iscsi_open, but is also recreated on iscsi_truncate. I don't have the context why this patch was introduced, but I would vote for introducing a bitmap_try_new and issue a warning if the allocation fails. The allocationmap is optional we can work without it. If the pointer is NULL its not used. Peter ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [Fwd: [PATCH v4 07/21] iscsi: Handle failure for potentially large allocations] 2014-08-22 7:40 ` [Qemu-devel] [Fwd: [PATCH v4 07/21] iscsi: Handle failure for potentially large allocations] Peter Lieven @ 2014-08-22 8:42 ` Kevin Wolf 2014-08-22 8:59 ` Peter Lieven 2014-08-24 16:30 ` Paolo Bonzini 0 siblings, 2 replies; 7+ messages in thread From: Kevin Wolf @ 2014-08-22 8:42 UTC (permalink / raw) To: Peter Lieven; +Cc: benoit.canet, Paolo Bonzini, maxa, qemu-devel, stefanha Am 22.08.2014 um 09:40 hat Peter Lieven geschrieben: > Am 22.08.2014 um 09:35 schrieb Peter Lieven: > > Some code in the block layer makes potentially huge allocations. Failure > > is not completely unexpected there, so avoid aborting qemu and handle > > out-of-memory situations gracefully. > > > > This patch addresses the allocations in the iscsi block driver. > > > > Signed-off-by: Kevin Wolf <kwolf@redhat.com> > > Acked-by: Paolo Bonzini <pbonzini@redhat.com> > > Reviewed-by: Benoit Canet <benoit@irqsave.net> > > Reviewed-by: Eric Blake <eblake@redhat.com> > > --- > > block/iscsi.c | 5 ++++- > > 1 file changed, 4 insertions(+), 1 deletion(-) > > > > diff --git a/block/iscsi.c b/block/iscsi.c > > index 84aa22a..06afa78 100644 > > --- a/block/iscsi.c > > +++ b/block/iscsi.c > > @@ -893,7 +893,10 @@ coroutine_fn iscsi_co_write_zeroes(BlockDriverState > > *bs, int64_t sector_num, > > nb_blocks = sector_qemu2lun(nb_sectors, iscsilun); > > > > if (iscsilun->zeroblock == NULL) { > > - iscsilun->zeroblock = g_malloc0(iscsilun->block_size); > > + iscsilun->zeroblock = g_try_malloc0(iscsilun->block_size); > > + if (iscsilun->zeroblock == NULL) { > > + return -ENOMEM; > > + } > > } > > > > iscsi_co_init_iscsitask(iscsilun, &iTask); > > Unfortunately, I missed that one. The zeroblock is typicalls 512 Byte or 4K depending > on the blocksize. I don't remember the details, but I think when I went through all drivers, I couldn't convince myself that a reasonable block size is enforced somewhere. So I just went ahead and converted the call to be on the safe side. It can never hurt anyway. > What is significantly larger is the allocationmap. It is typically created > on iscsi_open, but is also recreated on iscsi_truncate. I don't have the context why this > patch was introduced, but I would vote for introducing a bitmap_try_new and issue > a warning if the allocation fails. The allocationmap is optional we can work without it. > If the pointer is NULL its not used. Right, that one I missed because it doesn't directly use g_malloc(). Your proposal sounds good to me. Are you going to prepare a patch? Kevin ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [Fwd: [PATCH v4 07/21] iscsi: Handle failure for potentially large allocations] 2014-08-22 8:42 ` Kevin Wolf @ 2014-08-22 8:59 ` Peter Lieven 2014-08-24 16:30 ` Paolo Bonzini 1 sibling, 0 replies; 7+ messages in thread From: Peter Lieven @ 2014-08-22 8:59 UTC (permalink / raw) To: Kevin Wolf; +Cc: benoit.canet, Paolo Bonzini, maxa, qemu-devel, stefanha Am 22.08.2014 um 10:42 schrieb Kevin Wolf: > Am 22.08.2014 um 09:40 hat Peter Lieven geschrieben: >> Am 22.08.2014 um 09:35 schrieb Peter Lieven: >>> Some code in the block layer makes potentially huge allocations. Failure >>> is not completely unexpected there, so avoid aborting qemu and handle >>> out-of-memory situations gracefully. >>> >>> This patch addresses the allocations in the iscsi block driver. >>> >>> Signed-off-by: Kevin Wolf <kwolf@redhat.com> >>> Acked-by: Paolo Bonzini <pbonzini@redhat.com> >>> Reviewed-by: Benoit Canet <benoit@irqsave.net> >>> Reviewed-by: Eric Blake <eblake@redhat.com> >>> --- >>> block/iscsi.c | 5 ++++- >>> 1 file changed, 4 insertions(+), 1 deletion(-) >>> >>> diff --git a/block/iscsi.c b/block/iscsi.c >>> index 84aa22a..06afa78 100644 >>> --- a/block/iscsi.c >>> +++ b/block/iscsi.c >>> @@ -893,7 +893,10 @@ coroutine_fn iscsi_co_write_zeroes(BlockDriverState >>> *bs, int64_t sector_num, >>> nb_blocks = sector_qemu2lun(nb_sectors, iscsilun); >>> >>> if (iscsilun->zeroblock == NULL) { >>> - iscsilun->zeroblock = g_malloc0(iscsilun->block_size); >>> + iscsilun->zeroblock = g_try_malloc0(iscsilun->block_size); >>> + if (iscsilun->zeroblock == NULL) { >>> + return -ENOMEM; >>> + } >>> } >>> >>> iscsi_co_init_iscsitask(iscsilun, &iTask); >> Unfortunately, I missed that one. The zeroblock is typicalls 512 Byte or 4K depending >> on the blocksize. > I don't remember the details, but I think when I went through all > drivers, I couldn't convince myself that a reasonable block size is > enforced somewhere. So I just went ahead and converted the call to be on > the safe side. It can never hurt anyway. > >> What is significantly larger is the allocationmap. It is typically created >> on iscsi_open, but is also recreated on iscsi_truncate. I don't have the context why this >> patch was introduced, but I would vote for introducing a bitmap_try_new and issue >> a warning if the allocation fails. The allocationmap is optional we can work without it. >> If the pointer is NULL its not used. > Right, that one I missed because it doesn't directly use g_malloc(). > > Your proposal sounds good to me. Are you going to prepare a patch? will do. Peter ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [Fwd: [PATCH v4 07/21] iscsi: Handle failure for potentially large allocations] 2014-08-22 8:42 ` Kevin Wolf 2014-08-22 8:59 ` Peter Lieven @ 2014-08-24 16:30 ` Paolo Bonzini 2014-08-24 19:31 ` Peter Lieven 1 sibling, 1 reply; 7+ messages in thread From: Paolo Bonzini @ 2014-08-24 16:30 UTC (permalink / raw) To: Kevin Wolf, Peter Lieven; +Cc: benoit.canet, maxa, qemu-devel, stefanha Il 22/08/2014 10:42, Kevin Wolf ha scritto: > > Unfortunately, I missed that one. The zeroblock is typicalls 512 Byte or 4K depending > > on the blocksize. > > I don't remember the details, but I think when I went through all > drivers, I couldn't convince myself that a reasonable block size is > enforced somewhere. So I just went ahead and converted the call to be on > the safe side. It can never hurt anyway. Yeah, a malicious iSCSI target could have unreasonable block sizes. This means the minimum transfer size for SCSI devices could be on the order of half a GiB, and that could cause other unbounded allocations in the read-modify-write code. Are those protected too? Paolo ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [Fwd: [PATCH v4 07/21] iscsi: Handle failure for potentially large allocations] 2014-08-24 16:30 ` Paolo Bonzini @ 2014-08-24 19:31 ` Peter Lieven 2014-08-25 8:56 ` Paolo Bonzini 0 siblings, 1 reply; 7+ messages in thread From: Peter Lieven @ 2014-08-24 19:31 UTC (permalink / raw) To: Paolo Bonzini, Kevin Wolf; +Cc: benoit.canet, maxa, qemu-devel, stefanha Am 24.08.2014 um 18:30 schrieb Paolo Bonzini: > Il 22/08/2014 10:42, Kevin Wolf ha scritto: >>> Unfortunately, I missed that one. The zeroblock is typicalls 512 Byte or 4K depending >>> on the blocksize. >> I don't remember the details, but I think when I went through all >> drivers, I couldn't convince myself that a reasonable block size is >> enforced somewhere. So I just went ahead and converted the call to be on >> the safe side. It can never hurt anyway. > Yeah, a malicious iSCSI target could have unreasonable block sizes. Maybe we should just allow 512b or 4kb blocksize and refuse all other? Peter > > This means the minimum transfer size for SCSI devices could be on the > order of half a GiB, and that could cause other unbounded allocations in > the read-modify-write code. Are those protected too? > > Paolo ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [Fwd: [PATCH v4 07/21] iscsi: Handle failure for potentially large allocations] 2014-08-24 19:31 ` Peter Lieven @ 2014-08-25 8:56 ` Paolo Bonzini 2014-08-25 9:56 ` Peter Lieven 0 siblings, 1 reply; 7+ messages in thread From: Paolo Bonzini @ 2014-08-25 8:56 UTC (permalink / raw) To: Peter Lieven, Kevin Wolf; +Cc: benoit.canet, maxa, qemu-devel, stefanha Il 24/08/2014 21:31, Peter Lieven ha scritto: > Am 24.08.2014 um 18:30 schrieb Paolo Bonzini: >> Il 22/08/2014 10:42, Kevin Wolf ha scritto: >>>> Unfortunately, I missed that one. The zeroblock is typicalls 512 Byte or 4K depending >>>> on the blocksize. >>> I don't remember the details, but I think when I went through all >>> drivers, I couldn't convince myself that a reasonable block size is >>> enforced somewhere. So I just went ahead and converted the call to be on >>> the safe side. It can never hurt anyway. >> Yeah, a malicious iSCSI target could have unreasonable block sizes. > Maybe we should just allow 512b or 4kb blocksize and refuse > all other? At least CDs and DVDs use 2kb blocksize. :) Paolo ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [Fwd: [PATCH v4 07/21] iscsi: Handle failure for potentially large allocations] 2014-08-25 8:56 ` Paolo Bonzini @ 2014-08-25 9:56 ` Peter Lieven 0 siblings, 0 replies; 7+ messages in thread From: Peter Lieven @ 2014-08-25 9:56 UTC (permalink / raw) To: Paolo Bonzini, Kevin Wolf; +Cc: benoit.canet, maxa, qemu-devel, stefanha On 25.08.2014 10:56, Paolo Bonzini wrote: > Il 24/08/2014 21:31, Peter Lieven ha scritto: >> Am 24.08.2014 um 18:30 schrieb Paolo Bonzini: >>> Il 22/08/2014 10:42, Kevin Wolf ha scritto: >>>>> Unfortunately, I missed that one. The zeroblock is typicalls 512 Byte or 4K depending >>>>> on the blocksize. >>>> I don't remember the details, but I think when I went through all >>>> drivers, I couldn't convince myself that a reasonable block size is >>>> enforced somewhere. So I just went ahead and converted the call to be on >>>> the safe side. It can never hurt anyway. >>> Yeah, a malicious iSCSI target could have unreasonable block sizes. >> Maybe we should just allow 512b or 4kb blocksize and refuse >> all other? > At least CDs and DVDs use 2kb blocksize. :) power of 2 && <= 4096 ? > > Paolo > ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2014-08-25 9:56 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [not found] <00c425bd67fc66567dc683205f8f60f7.squirrel@ssl.dlhnet.de> 2014-08-22 7:40 ` [Qemu-devel] [Fwd: [PATCH v4 07/21] iscsi: Handle failure for potentially large allocations] Peter Lieven 2014-08-22 8:42 ` Kevin Wolf 2014-08-22 8:59 ` Peter Lieven 2014-08-24 16:30 ` Paolo Bonzini 2014-08-24 19:31 ` Peter Lieven 2014-08-25 8:56 ` Paolo Bonzini 2014-08-25 9:56 ` Peter Lieven
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).