Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3549964pxj; Mon, 24 May 2021 09:09:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQUivrrRbaSfi3foK07O4EwwkJDKcxt74JwnZPetPYHDfn+SFuQrk9eNMltayV5x4kjc8O X-Received: by 2002:a05:6e02:1d0b:: with SMTP id i11mr14771669ila.36.1621872590108; Mon, 24 May 2021 09:09:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621872590; cv=none; d=google.com; s=arc-20160816; b=pCbtVn9cAshvbJoKuP02XYqVRV+v5lR/jsjfD2CvoH8ShZmbLIXlPA7Yo+d5JAvhpS B9FRvv+gP8nv3azbFMAvgOAnRjWJiYByX33rPSiU4sEVoTv/+XpBCbudjvfIsXdkA599 O0OZJ67r/5X6sQys9BzFbeCQ71FPvh+ZOzuG2zychUXoC3tYfh7xb1dWelglMnka3tp6 OGMoqWMGy/qEKoDlZbRJ9aXviLSxa+5aJ8vCNHJdwPyq4djc9W1L1PGJgdyF06WR09BM 2sMWy6q50NaeSAmXl6UCGhjCCPhJqkVs+ff/YnV26J+ItuV3tH8OKDe8HDGFq0E/H9ny 7RQA== 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=hwbpkbmMCTLhTJCzsD3xfeAv4MKdt4vlZ+KtkDRP2zI=; b=qj1iGVX058Wo8dN1/3Xoc/baQgxpdbqhl0sJtt5nMoP0sOS9940gNJVmF98Xp03zCL LJPvTNkDl0Bw9aMo9UCQHQYJY0tg75Ax/aYOlVBwvOUEF3Bc5+3KXPCHe0bEsuDX9Mwd sWH5j9xOH/eVV573Nq/5Diqb1FM8+N1/UZ4Kxc/LIr2TzBSJIWbfaBl6DhKhzyLoVmCa 6wbC2bFPB0duj1et2LqdxfygMDaVPxAbk3wZBx6rTmxeB8nzUBD+lckyZAQdx/vK5KSa orVtKxmQewmYp+U2UMCqTV33X0IkjrggR7PpqitgxxwgHPx/SkTFeZwPf0Q0NtrWgjHg 6rgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=W7AUsz+B; 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 f184si14101359jac.102.2021.05.24.09.09.35; Mon, 24 May 2021 09:09:50 -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=W7AUsz+B; 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 S236013AbhEXQHp (ORCPT + 99 others); Mon, 24 May 2021 12:07:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:46680 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235676AbhEXQAE (ORCPT ); Mon, 24 May 2021 12:00:04 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 78ECF61461; Mon, 24 May 2021 15:45:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621871148; bh=AcoVqIUKAS83PBtxU0e3MSBpKP24FUWomHUDJy5W7Tc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W7AUsz+BDiuRZxS33ePZT39rW1YBB/Blh456vcvZT8JNlnUL6Xri7WC+lqZOG94yW BuNkbYn5AYRqFw+0rOTnrqQXL677BkOpIjQnuZE8KTczhOMEcRiaagAHoAUMKVRZ0S sgv0pQtecn7IyailxdKfR2N7vT6Q9IWQ/ZzTrCm4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mikulas Patocka , Mike Snitzer Subject: [PATCH 5.12 094/127] dm snapshot: fix crash with transient storage and zero chunk size Date: Mon, 24 May 2021 17:26:51 +0200 Message-Id: <20210524152338.035594414@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524152334.857620285@linuxfoundation.org> References: <20210524152334.857620285@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 @@ -1407,6 +1407,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; }