Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2523163yba; Mon, 15 Apr 2019 13:31:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqyBH/ZbD3ydy0QGewYVxqaP+edfccd4DIfsJLIo9/icBk0HRpj5wWeFFr80TkVldtP8ezWd X-Received: by 2002:a17:902:4381:: with SMTP id j1mr13390396pld.173.1555360300917; Mon, 15 Apr 2019 13:31:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555360300; cv=none; d=google.com; s=arc-20160816; b=csljBBTL8fHUsVzEy9hNdGvyGOfYwCAufYhR5ybfacJq+qKrYUdmUFMVPO9K94FZ6V f8LRSqeFrF/nzGc53GSptqDv9h4VQY4tM4klTpn1dv/jtkuq/7nbjgd6dD7khNBf0m27 NhA/wqWT6Q4IGwHg6ru5yy8+fwZ6XoWXB6A6hBE1NOaGr6GZYQ5SXM4frHkAGqBEW8ln 82Ue0x1S5WTqJie4YK5VPzF/6RRP0wRBSi2umkiUyXl7QH4HffIPygbRWjtywbpg+ESa /67sZxwVnSuBHWr8w020BjgPyLN7NlRhlaKiMMtV79fQEe+jVpBm6BE0JnCNYA+PODUt p1rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jhO+xN1uAsFOB+rwIVAuPVPeS4Frojo7Ckrh9UztSG4=; b=QTU77JTuGxm6xcG0cjZzBHwaKHXZ7q3a6GW1pQuSPG97tdwsLLu3/d7CWlb8SZAnDj moCBnicjARDwz1lds3DMDWHSq//mmVcxIACq6CpP+Zk/KzYOjT8AneVRElB0ZRGd/Pa+ 5k3itMngkTDMUxL5gDR4nMTqsDX7G4okzc3XfTayzDZuZvU9KWUXrFdfbk7Y5go3LoJ7 dVsOuBKQc9bVYhqRhwP6dRsGR3FPU6EBXHwznQFGqrQbRzY5/47ts7w+qGmXruRDNpot 0clW5SVkudYbZy5edV6jA5da7M1DCKEi+/sZE4Rahwv+l7El2HjRkdzvvp1PhdxGpBDO tK1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VwoOOhNW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g4si43694351plp.196.2019.04.15.13.31.24; Mon, 15 Apr 2019 13:31:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VwoOOhNW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727256AbfDOTIm (ORCPT + 99 others); Mon, 15 Apr 2019 15:08:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:44166 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730512AbfDOTIi (ORCPT ); Mon, 15 Apr 2019 15:08:38 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 46BE1218A1; Mon, 15 Apr 2019 19:08:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555355317; bh=ztni7lGS0IkxkmeDSu3uLSYLBFrCKNNIGd+xVUIG+Ok=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VwoOOhNWkBQKKTZWItLLsGneEtpMy6uC1j/LM+eIVmK96aomE9MWLcX292lmxYScK IJ3Oa2YI9S5h3cZtT0nFNwkLk79OObIMOo+33uz+nNyxcc8x5gzlSHGMJfHvF4JU/G cRM3vMjOymiHXXeJrViPNFJSyfyXakiY1eqc3ubY= 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.19 093/101] dm integrity: change memcmp to strncmp in dm_integrity_ctr Date: Mon, 15 Apr 2019 20:59:31 +0200 Message-Id: <20190415183745.293517351@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190415183740.341577907@linuxfoundation.org> References: <20190415183740.341577907@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mikulas Patocka commit 0d74e6a3b6421d98eeafbed26f29156d469bc0b5 upstream. If the string opt_string is small, the function memcmp can access bytes that are beyond the terminating nul character. In theory, it could cause segfault, if opt_string were located just below some unmapped memory. Change from memcmp to strncmp so that we don't read bytes beyond the end of the string. Cc: stable@vger.kernel.org # v4.12+ Signed-off-by: Mikulas Patocka Signed-off-by: Mike Snitzer Signed-off-by: Greg Kroah-Hartman --- drivers/md/dm-integrity.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/drivers/md/dm-integrity.c +++ b/drivers/md/dm-integrity.c @@ -3174,7 +3174,7 @@ static int dm_integrity_ctr(struct dm_ta journal_watermark = val; else if (sscanf(opt_string, "commit_time:%u%c", &val, &dummy) == 1) sync_msec = val; - else if (!memcmp(opt_string, "meta_device:", strlen("meta_device:"))) { + else if (!strncmp(opt_string, "meta_device:", strlen("meta_device:"))) { if (ic->meta_dev) { dm_put_device(ti, ic->meta_dev); ic->meta_dev = NULL; @@ -3193,17 +3193,17 @@ static int dm_integrity_ctr(struct dm_ta goto bad; } ic->sectors_per_block = val >> SECTOR_SHIFT; - } else if (!memcmp(opt_string, "internal_hash:", strlen("internal_hash:"))) { + } else if (!strncmp(opt_string, "internal_hash:", strlen("internal_hash:"))) { r = get_alg_and_key(opt_string, &ic->internal_hash_alg, &ti->error, "Invalid internal_hash argument"); if (r) goto bad; - } else if (!memcmp(opt_string, "journal_crypt:", strlen("journal_crypt:"))) { + } else if (!strncmp(opt_string, "journal_crypt:", strlen("journal_crypt:"))) { r = get_alg_and_key(opt_string, &ic->journal_crypt_alg, &ti->error, "Invalid journal_crypt argument"); if (r) goto bad; - } else if (!memcmp(opt_string, "journal_mac:", strlen("journal_mac:"))) { + } else if (!strncmp(opt_string, "journal_mac:", strlen("journal_mac:"))) { r = get_alg_and_key(opt_string, &ic->journal_mac_alg, &ti->error, "Invalid journal_mac argument"); if (r)