From patchwork Tue Feb 7 01:18:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Demi Marie Obenour X-Patchwork-Id: 53576 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2581977wrn; Mon, 6 Feb 2023 17:43:44 -0800 (PST) X-Google-Smtp-Source: AK7set8e/6Y/qb0Ftjr5tPCS36GG0lJyILfMY+rWOWga7ZPlUZIVskYvczrjjd5jZPMR7eThxXrV X-Received: by 2002:aa7:9aef:0:b0:592:e66f:6c7a with SMTP id y15-20020aa79aef000000b00592e66f6c7amr1404579pfp.20.1675734224047; Mon, 06 Feb 2023 17:43:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675734224; cv=none; d=google.com; s=arc-20160816; b=Zrr8MAIKVD6yCtZxDMIrb+6fkBT2BTs1pO508cwP5qV9c7Z2dIxcMRtHeDuKOBtU0R eS+DXcH/l4fU/IY3RrMXqHzc+n6D9hwi7zuLqty+h7xpsgVbZezOKEDs/HKcfF7DKby0 SreXRKM2zX622hS056QBc/jhrRK8avcL2eRE6AsgQNSVinet2xUIXLQWCibQhIK8UP/n bzQ7f+C1oz2eQNdtwbYI//io9TkA59lec2CgAajf5MlEKapWhIfhyi9my09YXi7Gqc4k ocD18CJgdJBdCap7fvHHRn8PQKvAhpzLRZpUQ8/eZGcnSm5NfrsKna2lXgEpnwHzjeDf kH7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:feedback-id:dkim-signature :dkim-signature; bh=zYPj50UvVEIOsgADXJp+oJsb7O+roahlWS7jztV/S9A=; b=dURD7UJrFhD8Ghzzu7yFkN+jxqmx0Uey7wV3Wa3h+3oONNwZI3WU+UL4+fd62imI8V wmpk/ldUjuEyJvrU6GJpUhynIrkn56nyCfmy8UJqoBTiY24CYlsovDjxUdiv5oZcq5MK W8LmZG7n3TEo+8OrYOQexnPwAv1v73hvK1AMv2Nvg2tXJns1q2QaV9XsyyMIvIxcGMtN 04uTW32/TbvTp3oAQnuCTL0xxScHF9EWg3OvmZHXKXLUJfM4jH+Kd/ZW3gD7KTr0TXok E7lt/pqv6eGqWT4WtDY8LVwyWnuX8gpSg+//b7gWsvJZLTzS0T3dRS4+C5dTWVoEveM+ +Wmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@invisiblethingslab.com header.s=fm3 header.b=dgkINF9M; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=TjtVQ2ZE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c4-20020aa781c4000000b005940003f68csi12464982pfn.356.2023.02.06.17.43.31; Mon, 06 Feb 2023 17:43:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@invisiblethingslab.com header.s=fm3 header.b=dgkINF9M; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=TjtVQ2ZE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229942AbjBGBTL (ORCPT + 99 others); Mon, 6 Feb 2023 20:19:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229525AbjBGBTJ (ORCPT ); Mon, 6 Feb 2023 20:19:09 -0500 Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 860AE1A4AF for ; Mon, 6 Feb 2023 17:19:08 -0800 (PST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 0D99332008FD; Mon, 6 Feb 2023 20:19:04 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 06 Feb 2023 20:19:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding:date :date:from:from:in-reply-to:message-id:mime-version:reply-to :sender:subject:subject:to:to; s=fm3; t=1675732744; x= 1675819144; bh=zYPj50UvVEIOsgADXJp+oJsb7O+roahlWS7jztV/S9A=; b=d gkINF9MygUXfd1bB4N9gmnLi686uzaq6pqgf+ye9RW5DDdi7SJEFDGDak/HvVCm+ Jsm6mLu6t274pUa82bhmrP0nSwPz26yG6CymyFblzcvq97dIyW5dlLV4fvZJVvDx Htko471RBmfnCZ6AJAims5MzFeYKb68UyKm6eBadkvheWl7pMZmMJAa3ghgh+OgG bCXlAIG2OI7B5xvkjnTBNgohd/wE0GDZIBrJgyKZRg86etnUeoliFcGKHyAPfJET zr6itNKCgcG2KLW0WmIgDz5bj9CpszH1HMunFz4GYMEK83dGTobHu6V9o/ZbndiK uyYT3Ngys6ED+cqFmJJWw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:message-id :mime-version:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1675732744; x=1675819144; bh=zYPj50UvVEIOsgADXJp+oJsb7O+roahlWS7 jztV/S9A=; b=TjtVQ2ZEIp1gCY+/1sP43JqJpyFvx7k95CwP8kXCM7DCQyuQFSl NkhncWZ0yAYLGZmwT/+fVcPqr675oPVmMvZIxMPd/dzXVm/lSueg96US154JsLCh 8jlDZPkZ5aQgu7xOrSTfY7+jcHvJvVcwRaAoaaeywjGV2lbC8yoU+FGgXH8yLE6C VhnDaZCjD7YA6bE6hpvSPWMIhSkjmuOuiY4fEmzSLAJsO+5MEhIR94Njq9tmiV0e ViS/NdLIJSd548kHJt6uU7ONVCIlHlxjvXkJyEqD2Ktbn0bDZS1Nt9vV6oTYViw9 ADE5+nmRRDW24UzwRnqmQSs200ZIEw97bzg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudegjedgfedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgggfestdekredtredttdenucfhrhhomhepffgvmhhiucfo rghrihgvucfqsggvnhhouhhruceouggvmhhisehinhhvihhsihgslhgvthhhihhnghhslh grsgdrtghomheqnecuggftrfgrthhtvghrnhepvdefgeekvdekgfffgeekhfeijedtffek hefhleehfeejueetgfelgefgtdevieelnecuvehluhhsthgvrhfuihiivgeptdenucfrrg hrrghmpehmrghilhhfrhhomhepuggvmhhisehinhhvihhsihgslhgvthhhihhnghhslhgr sgdrtghomh X-ME-Proxy: Feedback-ID: iac594737:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 6 Feb 2023 20:19:03 -0500 (EST) From: Demi Marie Obenour To: Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com Cc: Demi Marie Obenour , =?utf-8?q?Marek_Marczy?= =?utf-8?q?kowski-G=C3=B3recki?= , linux-kernel@vger.kernel.org Subject: [PATCH 1/2] Fail I/O to thin pool devices Date: Mon, 6 Feb 2023 20:18:48 -0500 Message-Id: <20230207011849.1343-1-demi@invisiblethingslab.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757134689837477098?= X-GMAIL-MSGID: =?utf-8?q?1757134689837477098?= A thin pool device currently just passes all I/O to its origin device, but this is a footgun: the user might not realize that tools that operate on thin pool metadata must operate on the metadata volume. This could have security implications. Fix this by failing all I/O to thin pool devices. Signed-off-by: Demi Marie Obenour --- drivers/md/dm-thin.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c index 64cfcf46881dc5d87d5dfdb5650ba9babd32cd31..d85fdbd782ae5426003c99a4b4bf53818cc85efa 100644 --- a/drivers/md/dm-thin.c +++ b/drivers/md/dm-thin.c @@ -3405,19 +3405,14 @@ static int pool_ctr(struct dm_target *ti, unsigned argc, char **argv) static int pool_map(struct dm_target *ti, struct bio *bio) { - int r; - struct pool_c *pt = ti->private; - struct pool *pool = pt->pool; - /* - * As this is a singleton target, ti->begin is always zero. + * Previously, access to the pool was passed down to the origin device. + * However, this turns out to be error-prone: if the user runs any of + * the thin tools on the pool device, the tools could wind up parsing + * potentially attacker-controlled data. This mistake has actually + * happened in practice. Therefore, fail all I/O on the pool device. */ - spin_lock_irq(&pool->lock); - bio_set_dev(bio, pt->data_dev->bdev); - r = DM_MAPIO_REMAPPED; - spin_unlock_irq(&pool->lock); - - return r; + return -EIO; } static int maybe_resize_data_dev(struct dm_target *ti, bool *need_commit) From patchwork Tue Feb 7 01:18:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Demi Marie Obenour X-Patchwork-Id: 53574 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2575200wrn; Mon, 6 Feb 2023 17:25:32 -0800 (PST) X-Google-Smtp-Source: AK7set/dAj+j2QBvrW8oMehZKyIlZRnLD79ZDKJaK35QINnH/Rc/Ry6ifQWQl5Mp7hJEu3jezO1f X-Received: by 2002:a17:90b:33c8:b0:22c:1bd6:77de with SMTP id lk8-20020a17090b33c800b0022c1bd677demr2079200pjb.3.1675733132256; Mon, 06 Feb 2023 17:25:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675733132; cv=none; d=google.com; s=arc-20160816; b=0+ZzFXuPZsAp/neLQvHwK1qwCqLbdbxPvlYK7Gy1IKmQHJMv+pyZb+G5PzZpWVpnIH bxIKdSdPSZr3nlzNXOalJjEXOVABlkDmQRAaWByN3AFxjcXx0AQjGdOEjh/shp24hmqV o3NvaQ8DqFTe32yCenPCPBpqs4Z2KVKUEEyE1uS9aPrBjAwesVGeqXnKvCRbpZQKn92x C445+hSbxyIPuMhIHVIRmBNuSKB3t6JbCSTcnJMbByKTDXuV5h6RXDbGdMxKCRdF8PnM nON1i1h/6/yneW6DK7QCn1gktLRnB7sG3MyZkl8hW88f+hb+MkMPkvP45d95H2mWNBRE u3lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=AHlkp+EDvWtN8qpqD5t39xLQ6Cx8b01B9eJKee86CLk=; b=krxhRQrML3muvUQU+nVTnN+4dUR6WlFyGUepo0jYp2qtZA1kQQR2qGKlz4EClmRQPC 3S5cvq/oKvrpTCunYSo+WYM9q6bLPXYdZ9Gbh6CQyB0/CDzfxUdYCN1NCF/mUwb+JHDN IGMGwRWXyz7oxpwUKz6hjW5GeRgD9fGj4Ie6cyQj5FwakCAhmRfj1qd7GKgMu6xiCD5M /qq9p0NN7cO9E/Iq7FgLP6GPMJMRuacCXcULwi2BhzoTy0J89E4YDo/HgzZOxYx9PJgL g5cv6+noB0ulVWjBuYLJv7Ws6k0M+HD/+Ux6VmyQMiS77RVvMvvs6S/mrHgjZeMLaVrZ NBGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@invisiblethingslab.com header.s=fm3 header.b="BXAZT/zF"; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b="GpPCG//M"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lk17-20020a17090b33d100b002268e9e9b97si22756733pjb.31.2023.02.06.17.25.19; Mon, 06 Feb 2023 17:25:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@invisiblethingslab.com header.s=fm3 header.b="BXAZT/zF"; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b="GpPCG//M"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229525AbjBGBTM (ORCPT + 99 others); Mon, 6 Feb 2023 20:19:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229766AbjBGBTK (ORCPT ); Mon, 6 Feb 2023 20:19:10 -0500 Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66C331E1CB for ; Mon, 6 Feb 2023 17:19:09 -0800 (PST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 8687F320090A; Mon, 6 Feb 2023 20:19:08 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Mon, 06 Feb 2023 20:19:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm3; t= 1675732748; x=1675819148; bh=AHlkp+EDvWtN8qpqD5t39xLQ6Cx8b01B9eJ Kee86CLk=; b=BXAZT/zFT53tlxNpcb5s5G19r/2/Mgmk01yp8uB4d8nS1LGG4yO 88dWH29zbVkgXYdk6XroaPQrJpQwG0ztEcWMXEAsmKQiWMRFmVHBhzPEvRLvOVWw mo3nlyrQAwlw/c4vGF9vT5qMixrkfJgKrbMNg2iJXlQoxUCct6o5mtzTHdy7CHGP QievxJnXjiulPMzxyxkNIMYgeXp1dbQ0jfYPEaNE+rjy6I1vXhaZvXv5+J+/R2Qv DUZFxK1otx9fcdw0L/kMySfSveG+O8JJ9y1RoAW+wMphgLxQ+vKC66EdpVHG+bfV 9UDOg9J9C0+x4wMLmVtfkOAaRsGO6ArxlLw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1675732748; x=1675819148; bh=AHlkp+EDvWtN8 qpqD5t39xLQ6Cx8b01B9eJKee86CLk=; b=GpPCG//MKEqygcMwbszcpqmGK/zNj zNF8Fdam9B1AgYI3TGjJKmtz/i4W5wI4+Gy6ypS3aMn/mIoRA3hlEdYwJG3wm7HQ TvLscSSA6nrLWwSXHR+JNggQpa3dbJ7QHgF23zb4hZx5lGk1YJfy06eq7zGRKX6E 6BuTS4CKmu9n39QaVeTEvp3ezMrhKh8OFQlR3XAznKVNpbRhLQLXc4Hexa5yiZtu v8Nwt38grg9Pu/yHaPvz3LQLjelHd4UlPJKlNPeSDXQKAJz8TOmgtqSqHbFlz3/F 2Yb/RMql7FsYhv38P549rP5BHeDazi58+d8R/e7hJ7G5Is6wciCDd5esQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudegjedgfedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepffgvmhhi ucforghrihgvucfqsggvnhhouhhruceouggvmhhisehinhhvihhsihgslhgvthhhihhngh hslhgrsgdrtghomheqnecuggftrfgrthhtvghrnhepjeffjefggfeugeduvedvjeekgfeh gffhhfffjeetkeelueefffetfffhtdduheetnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepuggvmhhisehinhhvihhsihgslhgvthhhihhnghhs lhgrsgdrtghomh X-ME-Proxy: Feedback-ID: iac594737:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 6 Feb 2023 20:19:07 -0500 (EST) From: Demi Marie Obenour To: Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com Cc: Demi Marie Obenour , =?utf-8?q?Marek_Marczy?= =?utf-8?q?kowski-G=C3=B3recki?= , linux-kernel@vger.kernel.org Subject: [PATCH 2/2] dm-thin: Allow specifying an offset Date: Mon, 6 Feb 2023 20:18:49 -0500 Message-Id: <20230207011849.1343-2-demi@invisiblethingslab.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230207011849.1343-1-demi@invisiblethingslab.com> References: <20230207011849.1343-1-demi@invisiblethingslab.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757133544682627718?= X-GMAIL-MSGID: =?utf-8?q?1757133544682627718?= This allows exposing only part of a thin volume without having to layer dm-linear. One use-case is a hypervisor replacing a partition table. Signed-off-by: Demi Marie Obenour --- drivers/md/dm-thin.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c index d85fdbd782ae5426003c99a4b4bf53818cc85efa..87f14933375b050a950a5f58e98c13b4d28f6af0 100644 --- a/drivers/md/dm-thin.c +++ b/drivers/md/dm-thin.c @@ -357,6 +357,7 @@ struct thin_c { */ refcount_t refcount; struct completion can_destroy; + u64 offset; }; /*----------------------------------------------------------------*/ @@ -1180,9 +1181,9 @@ static void process_prepared_discard_passdown_pt1(struct dm_thin_new_mapping *m) discard_parent = bio_alloc(NULL, 1, 0, GFP_NOIO); discard_parent->bi_end_io = passdown_endio; discard_parent->bi_private = m; - if (m->maybe_shared) - passdown_double_checking_shared_status(m, discard_parent); - else { + if (m->maybe_shared) + passdown_double_checking_shared_status(m, discard_parent); + else { struct discard_op op; begin_discard(&op, tc, discard_parent); @@ -4149,7 +4150,7 @@ static int thin_ctr(struct dm_target *ti, unsigned argc, char **argv) mutex_lock(&dm_thin_pool_table.mutex); - if (argc != 2 && argc != 3) { + if (argc < 2 || argc > 4) { ti->error = "Invalid argument count"; r = -EINVAL; goto out_unlock; @@ -4168,7 +4169,8 @@ static int thin_ctr(struct dm_target *ti, unsigned argc, char **argv) bio_list_init(&tc->retry_on_resume_list); tc->sort_bio_list = RB_ROOT; - if (argc == 3) { + /* Use "/" to indicate "no origin device" while providing an offset */ + if (argc >= 3 && strcmp(argv[2], "/")) { if (!strcmp(argv[0], argv[2])) { ti->error = "Error setting origin device"; r = -EINVAL; @@ -4196,6 +4198,23 @@ static int thin_ctr(struct dm_target *ti, unsigned argc, char **argv) goto bad_common; } + tc->offset = 0; + if (argc > 3) { + sector_t sector_offset; + + if (kstrtoull(argv[3], 10, &tc->offset)) { + ti->error = "Invalid offset"; + r = -EINVAL; + goto bad_common; + } + + if (check_add_overflow(tc->offset, ti->len, §or_offset)) { + ti->error = "Offset + len overflows sector_t"; + r = -EINVAL; + goto bad_common; + } + } + pool_md = dm_get_md(tc->pool_dev->bdev->bd_dev); if (!pool_md) { ti->error = "Couldn't get pool mapped device"; @@ -4285,8 +4304,9 @@ static int thin_ctr(struct dm_target *ti, unsigned argc, char **argv) static int thin_map(struct dm_target *ti, struct bio *bio) { - bio->bi_iter.bi_sector = dm_target_offset(ti, bio->bi_iter.bi_sector); + struct thin_c *tc = ti->private; + bio->bi_iter.bi_sector = dm_target_offset(ti, bio->bi_iter.bi_sector) + tc->offset; return thin_bio_map(ti, bio); }