Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3529572pxj; Mon, 24 May 2021 08:45:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxilcMILcsULaulgiKYKBk6YfMikchYPvYG3VR9uCAJrwqTe1Nv0145MArfTPbcgmC4H3vC X-Received: by 2002:a05:6402:3551:: with SMTP id f17mr4731582edd.313.1621871107022; Mon, 24 May 2021 08:45:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621871107; cv=none; d=google.com; s=arc-20160816; b=lBcaG4kePE8RICfu0h1WVkKjh+opSgxh0M5ZaEUQ8R16yFrWRdrOuLPFZ79hMbQoga pNMZ4l0jv8ARJMygViOjUHtdXbGn9OvRRjYBs7onid1TE553j780I1HLdT+j7g/lYIYd AtrB0eHKIcmrgPvuO2VwFapQxYfbnG/BE2gMMOuIU0EPoLmmVQY5g4DDOAyRSXMzZPO0 4RyprSjHbOTYa0W91ZQPq0tiv/y7ghr6EWW3oDKzYH34zwVq4qaSkgnbGcBXbWkmWZ3f VuWhZeYoTEY4tLE+VYqCugWqgGW1s/SGGTUH9c50nAxC49H5iMdXFqmQ04Ncm0jfYXqD Z3+w== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=17TzuIPEmo3VtwYdJQqQa66OyG/0EIoj9yqcbkNytvg=; b=vnDgXp8dF1KM+A1s2k8xIQK5l/thHsmxL3qOhCBYQjAZdNCS0wmPEEJ7SpZY7JoqVQ IV1TmuCHO81MOFX0ieL12kSK6UOtxFpFPoAMtEI7pT0b0Ole8ccSNsqBWt4DFc8qXN9J mqfh8GNj1yKanWtzjl9yuBLOhby0E7zeZbQKph5IVgBGqNyxpUmY5l7IT6BAU57r1MuL lBjCE0xsPJ5Zkm+p4D9cXamV/8iRmx1ONioZ7IwLdFHmSTUXzEztBeAq6FbpgL/GCiz4 ZPmxPKi7tCxiDyW+nwo38rQaluTVNL0Rs/ufVo4aWX3RMRDwYx3xgottxkVg2OU+1ie0 CVEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=X6BO2S6Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hr15si6918707ejc.526.2021.05.24.08.44.43; Mon, 24 May 2021 08:45:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=X6BO2S6Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234622AbhEXPo0 (ORCPT + 99 others); Mon, 24 May 2021 11:44:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:58234 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233879AbhEXPkV (ORCPT ); Mon, 24 May 2021 11:40:21 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8C0506143A; Mon, 24 May 2021 15:34:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621870456; bh=cCJCMC36Ge3NvLa2sMCwovOSbnmUC5nuuXymeLcvdQs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X6BO2S6YbylhmDEAxPxu1ClK7j1HbNnqDaqPd02fwPK15DkIc5Enj/rufz7zZZql8 MHK+oMKEqoVgL3UhBw8EdM/0ZRzG0PLKF2yMhYpszHP5gQ/yyB+AZdiIuDd2cK+TjY s/Xg8EvTotA+wlYxYYSxF/Af9NTx3fYQoUoU7SAI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mikulas Patocka , Mike Snitzer Subject: [PATCH 4.14 15/37] dm snapshot: fix crash with transient storage and zero chunk size Date: Mon, 24 May 2021 17:25:19 +0200 Message-Id: <20210524152324.709750069@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524152324.199089755@linuxfoundation.org> References: <20210524152324.199089755@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mikulas Patocka commit c699a0db2d62e3bbb7f0bf35c87edbc8d23e3062 upstream. The following commands will crash the kernel: modprobe brd rd_size=1048576 dmsetup create o --table "0 `blockdev --getsize /dev/ram0` snapshot-origin /dev/ram0" dmsetup create s --table "0 `blockdev --getsize /dev/ram0` snapshot /dev/ram0 /dev/ram1 N 0" The reason is that when we test for zero chunk size, we jump to the label bad_read_metadata without setting the "r" variable. The function snapshot_ctr destroys all the structures and then exits with "r == 0". The kernel then crashes because it falsely believes that snapshot_ctr succeeded. In order to fix the bug, we set the variable "r" to -EINVAL. Signed-off-by: Mikulas Patocka Cc: stable@vger.kernel.org Signed-off-by: Mike Snitzer Signed-off-by: Greg Kroah-Hartman --- drivers/md/dm-snap.c | 1 + 1 file changed, 1 insertion(+) --- a/drivers/md/dm-snap.c +++ b/drivers/md/dm-snap.c @@ -1285,6 +1285,7 @@ static int snapshot_ctr(struct dm_target if (!s->store->chunk_size) { ti->error = "Chunk size not set"; + r = -EINVAL; goto bad_read_metadata; }