Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 2 Nov 2019 09:22:20 +0000 (UTC)
From:      Toomas Soome <tsoome@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r354248 - stable/12/stand/libsa/zfs
Message-ID:  <201911020922.xA29MKij075005@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: tsoome
Date: Sat Nov  2 09:22:20 2019
New Revision: 354248
URL: https://svnweb.freebsd.org/changeset/base/354248

Log:
  MFC r354119:
  loader: rs_alloc() may return NULL
  
  rs_alloc() in zfs reader code may return NULL, so we need to check the return
  value and error out if needed.

Modified:
  stable/12/stand/libsa/zfs/zfsimpl.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/stand/libsa/zfs/zfsimpl.c
==============================================================================
--- stable/12/stand/libsa/zfs/zfsimpl.c	Sat Nov  2 04:01:39 2019	(r354247)
+++ stable/12/stand/libsa/zfs/zfsimpl.c	Sat Nov  2 09:22:20 2019	(r354248)
@@ -840,12 +840,17 @@ vdev_indirect_remap(vdev_t *vd, uint64_t offset, uint6
 	list_t stack;
 	spa_t *spa = vd->spa;
 	zio_t *zio = arg;
+	remap_segment_t *rs;
 
 	list_create(&stack, sizeof (remap_segment_t),
 	    offsetof(remap_segment_t, rs_node));
 
-	for (remap_segment_t *rs = rs_alloc(vd, offset, asize, 0);
-	    rs != NULL; rs = list_remove_head(&stack)) {
+	rs = rs_alloc(vd, offset, asize, 0);
+	if (rs == NULL) {
+		printf("vdev_indirect_remap: out of memory.\n");
+		zio->io_error = ENOMEM;
+	}
+	for ( ; rs != NULL; rs = list_remove_head(&stack)) {
 		vdev_t *v = rs->rs_vd;
 		uint64_t num_entries = 0;
 		/* vdev_indirect_mapping_t *vim = v->v_mapping; */
@@ -853,6 +858,9 @@ vdev_indirect_remap(vdev_t *vd, uint64_t offset, uint6
 		    vdev_indirect_mapping_duplicate_adjacent_entries(v,
 		    rs->rs_offset, rs->rs_asize, &num_entries);
 
+		if (num_entries == 0)
+			zio->io_error = ENOMEM;
+
 		for (uint64_t i = 0; i < num_entries; i++) {
 			vdev_indirect_mapping_entry_phys_t *m = &mapping[i];
 			uint64_t size = DVA_GET_ASIZE(&m->vimep_dst);
@@ -865,9 +873,18 @@ vdev_indirect_remap(vdev_t *vd, uint64_t offset, uint6
 			vdev_t *dst_v = vdev_lookup_top(spa, dst_vdev);
 
 			if (dst_v->v_read == vdev_indirect_read) {
-				list_insert_head(&stack,
-				    rs_alloc(dst_v, dst_offset + inner_offset,
-				    inner_size, rs->rs_split_offset));
+				remap_segment_t *o;
+
+				o = rs_alloc(dst_v, dst_offset + inner_offset,
+				    inner_size, rs->rs_split_offset);
+				if (o == NULL) {
+					printf("vdev_indirect_remap: "
+					    "out of memory.\n");
+					zio->io_error = ENOMEM;
+					break;
+				}
+
+				list_insert_head(&stack, o);
 			}
 			vdev_indirect_gather_splits(rs->rs_split_offset, dst_v,
 			    dst_offset + inner_offset,



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201911020922.xA29MKij075005>