From nobody Tue May 26 04:51:44 2026 Received: from mail-yx1-f48.google.com (mail-yx1-f48.google.com [74.125.224.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 151C22E7185 for ; Tue, 12 May 2026 05:10:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778562646; cv=none; b=hUIGNRmQwvvCbcp0drU1XC/Z1ylpnyIkU27YgUdDnihaTiniUfzzIgiI9h0fRrh3V+WW1YQbws6RNFI5jafVTgF7E+pevDPywZZRtW41WE1duP2Vdf7tqfPhhN1S+kheCW9l9I5rhtpphZ/gI/yHX9XtNUw4XhIg6XsuZxccgA0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778562646; c=relaxed/simple; bh=dcEmVjoKdHpiPTjQ1tFHqV8QJTHDEZBuy1AIrj3Rq3Q=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Bp812H77r7egkXG0oy3fAbUKXd6Sirer+z5scftexJJaCM/cgIKbcIot3o05kE4hv2Em1MH20K10s0QOJN5174CDgDAfe8EQ4fC9kYcYpA4UOgYNAXyf5xuMOcGGFtn2DaZN0cik8dKxSeONqyMprE/b6DtRYT4REMrMwm8XH24= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=sung-woo.kim; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=74.125.224.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=sung-woo.kim Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-yx1-f48.google.com with SMTP id 956f58d0204a3-6587cee8b57so5425792d50.2 for ; Mon, 11 May 2026 22:10:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778562644; x=1779167444; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=i+6QzfD1TPj/UYCxT/pRvXekIh5WoFE0MUpGbazQu3A=; b=arxsBVpr5weo7oF95H51IdlHMBusbbqs5YEcN9427uK6w0kRC0oWf7e8BbpvcwbXu2 QaDcUPwCyD+2T2um2V5W2wC4PzGTVLJFQx6QR956NUidWoitLwwdMM7qCBihB4YLy7xK o2pC8DSuCDbbpPuPKHyulLCp85WSV2Rwq5lRFdJcFgaPQCJxhXF/7NkNZi68ZfFPAyRU /a+J4cLOlpS3Rg8OD/nNZc6EAP2mtQ+V5IiAvdXBBuioI0mgKqBev+TaHwXYDl6cM+N7 0JAT8v8cXbJXP3IjndpgnXGrp9IRrZWXn6zgh86X6P/X+Z8epxmX4ZY1+3te/+sz36XM av5Q== X-Forwarded-Encrypted: i=1; AFNElJ8ni0R8cxkaY4r6L5C+NyTJL90mAFXfTYlY+rKdhEGNzBVgsjo0Z26bIJOUgC2NIDZqJOiXRfhFZSU528E=@vger.kernel.org X-Gm-Message-State: AOJu0Yym/Xz6NGpyxOKDWZnzco0wJ27Pwp6iMSOtWvPysGM7UKF0/KcP FDI+KyO1F6rQsLxtS17CMR0AZzgsr5zvEzFNb7Pd2HeqJVBgCDcnOrov X-Gm-Gg: Acq92OHuNoEWDkkTnDzLW6HHnC59S3UUh0WRjlFJYpgsIMf37FM+HgZS3UmQOiVBI4/ DtefKZULr03CFd+AMJxMGN4V8bB9W+V7oZhhJ/PJvszcaUII4x4at9QiYccFgxrTkAAky/0c7tt jViQ0cUiDVaq+B/O845HdAMjQUpe/fICHHYMWYk+hdoTm1jxbFyDu5JU2UTHzR2cao2Y6of4zC6 cemjNguq5YNM0VXozCHJDTH8ct/2OOiqrsXEs68y28BvDpsi6AbrC/e8keIbBSYOT5P73y9r0kG Hi9EkmVAXfzF7MsnV4/PAtNwo+7WYHSbY1dcOWvX3qMdQMW4aBlXSosq7Wj0QFwOpDtQsdvpDKi vp2S063A3q1QuV5uJDBuYRE/n3NamMl1l0Ule91hIFsaHXjILE6mYBZjn/wGl3Nm6gEQIs+iQic TWh8MGPniJhA== X-Received: by 2002:a05:690e:4087:b0:65c:65ae:be23 with SMTP id 956f58d0204a3-65de128085fmr1332746d50.45.1778562644054; Mon, 11 May 2026 22:10:44 -0700 (PDT) Received: from tofu.. ([128.210.0.165]) by smtp.googlemail.com with ESMTPSA id 00721157ae682-7bd6685bfd4sm159239347b3.33.2026.05.11.22.10.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 22:10:42 -0700 (PDT) From: Sungwoo Kim To: Jens Axboe , Keith Busch Cc: Shin'ichiro Kawasaki , Sungwoo Kim , Chao Shi , Weidong Zhu , Dave Tian , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5] block: bio-integrity: Fix null-ptr-deref in bio_integrity_map_user() Date: Tue, 12 May 2026 01:09:29 -0400 Message-ID: <20260512050929.541397-2-iam@sung-woo.kim> X-Mailer: git-send-email 2.47.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" pin_user_pages_fast() can partially succeed and return the number of pages that were actually pinned. However, the bio_integrity_map_user() does not handle this partial pinning. This leads to a general protection fault since bvec_from_pages() dereferences an unpinned page address, which is 0. To fix this, add a check to verify that all requested memory is pinned. If partial pinning occurs, unpin the memory and return -EFAULT. Reproducer in blktest: https://github.com/linux-blktests/blktests/pull/244 Tested by Shin'ichiro: https://lore.kernel.org/linux-block/20260427040926.987166-3-iam@sung-woo.ki= m/T/#me17b14f2b2de12cf012b04d297e24cae667a6bd9 Kernel Oops: Oops: general protection fault, probably for non-canonical address 0xdffffc= 0000000001: 0000 [#1] SMP KASAN NOPTI KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f] CPU: 0 UID: 0 PID: 1061 Comm: nvme-passthroug Not tainted 7.0.0-11783-g9095= 7f9314e8-dirty #16 PREEMPT(lazy) Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.17.0-0-gb= 52ca86e094d-prebuilt.qemu.org 04/01/2014 RIP: 0010:bio_integrity_map_user.cold+0x1b0/0x9d6 Fixes: 492c5d455969 ("block: bio-integrity: directly map user buffers") Acked-by: Chao Shi Acked-by: Weidong Zhu Acked-by: Dave Tian Signed-off-by: Sungwoo Kim --- V4: https://lore.kernel.org/linux-block/20260427040926.987166-3-iam@sung-wo= o.kim/T/#ma69d880eb4dba82bc55cad882d42f2b674c473b6 V4->V5 - Fixed a coding style issue, addressing a Jens's comments. Thank you Shin'ichiro for testing V4. It'd be great if you could test V5 as well. V5 is the same as V4 except for the coding style fix, thus I don't expect any functional change. block/bio-integrity.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/block/bio-integrity.c b/block/bio-integrity.c index e54c6e06e1cb..856a5f16155e 100644 --- a/block/bio-integrity.c +++ b/block/bio-integrity.c @@ -403,6 +403,24 @@ int bio_integrity_map_user(struct bio *bio, struct iov= _iter *iter) if (unlikely(ret < 0)) goto free_bvec; =20 + /* + * Handle partial pinning. This can happen when pin_user_pages_fast() + * returns fewer pages than requested. + */ + if (user_backed_iter(iter) && unlikely(ret !=3D bytes)) { + if (ret > 0) { + int npinned =3D DIV_ROUND_UP(offset + ret, PAGE_SIZE); + int i; + + for (i =3D 0; i < npinned; i++) + unpin_user_page(pages[i]); + } + if (pages !=3D stack_pages) + kvfree(pages); + ret =3D -EFAULT; + goto free_bvec; + } + nr_bvecs =3D bvec_from_pages(bvec, pages, nr_vecs, bytes, offset, &is_p2p); if (pages !=3D stack_pages) --=20 2.47.3