Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2404810lqp; Sun, 24 Mar 2024 18:08:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXsIj+umywCMSOG5Q9rn3NvGE+U+NF7kq9Z9v6ZWPfUgXS61CPGl5X+6kqAgqD8/prVO0wyvSBcZiG4pqnREdPwu7+ZPiIuPCrhy/34eA== X-Google-Smtp-Source: AGHT+IHvGpnVX/2ud3OvMzWybuDEtyB7PcgvZFLkTy+df9vNeJHybAcLiul7yioDbz6tH5vMnMDk X-Received: by 2002:a17:906:184d:b0:a46:c11d:dd01 with SMTP id w13-20020a170906184d00b00a46c11ddd01mr3582673eje.50.1711328898315; Sun, 24 Mar 2024 18:08:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711328898; cv=pass; d=google.com; s=arc-20160816; b=n8xMP57bwQs/O2hniXt+/7aWLbyUp8RpZTDFwImAGjNmRgzkbQjBzUGHs24Xjrz5Eq M31aunvNK+MV5dlL8tZg49/2euh1NmljZDt+UAmQvhhKg4SmNETZBb4UpxeEYBbgDatD juRyZiPnkhyNs8jxPax+sFFW4J+NvVWwBBaJXTIuQXcHpU5hZhi+6FF4WBVmWUhiQe82 Ivl5Btp37HtC+vS+tLgYWPOlj8laubf0za2G/MuGgbWYj5FQFWOv8EBnYCo5sVOb1fFi y75cnB5LFsA8o0x+ZFebZf03hSZ4gzFF9pb07paNkqhTIU8rMliMQF5CN81TbYenFhgt Rn0A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=n9wQ3dXlmENghXY2Mq/i1M67Hrn5q4UQtzhZwPf1PXM=; fh=gztaZlEV/IhaCTI9OXrOTx7G3T0xX7o1SJxZFm84PTI=; b=zbJD1UqOePKGdXvN2qwft1DOLvyrdnEXuzmoVKhQ501kai0GbNk2vO3iBoPiFxClJX pIuOoPmgvRotCGhfbsjjTl1CzfPtksze0Ov6xgFtGNluuZ3pNszWkpVOncwvnPcf7xZM 4LiSDx9iP5IRbRknuXjGEf5BNMMm7Lb2UYEtq6oPtaJHZ++jDmic0bh0u7LTbzGUiBHm 9vYW4BcDGI9bJ74IHzlVWQeGzDpM++KMYsI1q1njZCPS2YX6HE4mRAPhxN1mnynhRtQE hNMqkdBmGj+KHCloh/1lXhhZDVY80eCgv2Um/o7cjBPDUWzvlc2uT0ODdupT0DxiOZqm 4H0A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=njw8ca5x; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113580-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113580-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id l1-20020a1709067d4100b00a4635b643afsi1984209ejp.985.2024.03.24.18.08.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 18:08:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113580-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=njw8ca5x; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113580-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113580-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 1198B1F23D2B for ; Mon, 25 Mar 2024 01:08:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EFAA81C9ECF; Sun, 24 Mar 2024 22:46:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="njw8ca5x" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0FBCD1C9EB1; Sun, 24 Mar 2024 22:46:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320384; cv=none; b=tOtNzxlQDL21enzF0hCDLWh26c9cBsm7nvccgzHDoMd1nyh7B6767ZMc5hoWREVyWMRJ89hdpYjhdT6C45TJn4zDXzWlULbF8h1qXbbTN2omPfClN/PTn8Z5RkcGZGKSjufBGTsP/B2wUdHB70YduxeaLJ3eOoX5AvC9wIBQ7MU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320384; c=relaxed/simple; bh=qPqRV2EP6kpC6/451Xi6W2Alk4HTibFzdN5q6rAgiqw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BNp+IwE6KqaLbGOzBUxCRFLTGEKQXfbZmX0ggOypNb+K83Vxd0ehJj7JJustw+zllBBxOvK1jeJfrO7xTCXHBHQyhOXA+FGQDgyXxf3nMktVRs8AJw5aQivXck+q+dpJHm1D6DXYAM8l7oMyKXKofCJ4UOWVyLQwSts94IYR/iM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=njw8ca5x; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01A77C43390; Sun, 24 Mar 2024 22:46:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320383; bh=qPqRV2EP6kpC6/451Xi6W2Alk4HTibFzdN5q6rAgiqw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=njw8ca5xSVXWPXWrIpmGL6/spAV/81oJCtXKd8Id0M36NR3vplhnKou+ZDxUlIzAR ed8e/+eHrq3AXz/RhnEAmmwQ1jgrK2tvOZco/tI3ocwt2Uu6qbtUM3cYM4pwiD+i1r ZsLKQjxzzOFNw6bF87s39bT4hhFl45svhCuB3VDt566HTX2NnvvMKL5CvKFjto9peU 2AZggU/dyOPbfyiZcuYjXTWDXMIKt2NczSBaPCotdv5wvDV4MsC4cyP3WlPizNAV1I 3JPEDbiShWw1Oh7Cb2qr21xGIWv/gGZvnapl90fH7jX5TKrgHocT/eOivsJNIKv3lt OX6b/+VGrqtMQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Mikulas Patocka , Mike Snitzer , Sasha Levin Subject: [PATCH 6.8 689/715] dm-integrity: fix a memory leak when rechecking the data Date: Sun, 24 Mar 2024 18:34:28 -0400 Message-ID: <20240324223455.1342824-690-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Mikulas Patocka [ Upstream commit 55e565c42dce81a4e49c13262d5bc4eb4c2e588a ] Memory for the "checksums" pointer will leak if the data is rechecked after checksum failure (because the associated kfree won't happen due to 'goto skip_io'). Fix this by freeing the checksums memory before recheck, and just use the "checksum_onstack" memory for storing checksum during recheck. Fixes: c88f5e553fe3 ("dm-integrity: recheck the integrity tag after a failure") Signed-off-by: Mikulas Patocka Signed-off-by: Mike Snitzer Signed-off-by: Sasha Levin --- drivers/md/dm-integrity.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/md/dm-integrity.c b/drivers/md/dm-integrity.c index 1fc901df84eb1..f194ce6bfacb5 100644 --- a/drivers/md/dm-integrity.c +++ b/drivers/md/dm-integrity.c @@ -1848,12 +1848,12 @@ static void integrity_metadata(struct work_struct *w) r = dm_integrity_rw_tag(ic, checksums, &dio->metadata_block, &dio->metadata_offset, checksums_ptr - checksums, dio->op == REQ_OP_READ ? TAG_CMP : TAG_WRITE); if (unlikely(r)) { + if (likely(checksums != checksums_onstack)) + kfree(checksums); if (r > 0) { - integrity_recheck(dio, checksums); + integrity_recheck(dio, checksums_onstack); goto skip_io; } - if (likely(checksums != checksums_onstack)) - kfree(checksums); goto error; } -- 2.43.0