All of lore.kernel.org
 help / color / mirror / Atom feed
* [dm-crypt] [PATCH] libdevmapper: correctly compare major and minor versions
@ 2013-11-13 21:27 Dave Reisner
  2013-11-14  7:38 ` Milan Broz
  0 siblings, 1 reply; 2+ messages in thread
From: Dave Reisner @ 2013-11-13 21:27 UTC (permalink / raw)
  To: dm-crypt; +Cc: Dave Reisner

Previously, this code could incorrectly identify a version of crypt or
dm due to the way it compared versions. For example, if a feature was
gated on crypt version 1.5, it would disable the feature for crypt
version 2.2.
---
Apologies if I've misunderstood the intent here, but this patch seems like the
correct thing to do. I suspect that this bug hasn't been encountered before
because of the historical versioning of cryptsetup (which has only ever matched
1.x.y).

 lib/libdevmapper.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/lib/libdevmapper.c b/lib/libdevmapper.c
index 2fa5c8b..48bb2b0 100644
--- a/lib/libdevmapper.c
+++ b/lib/libdevmapper.c
@@ -100,6 +100,18 @@ static void set_dm_error(int level,
 
 static int _dm_simple(int task, const char *name, int udev_wait);
 
+static int _dm_satisfies_version(unsigned target_maj, unsigned target_min,
+		unsigned actual_maj, unsigned actual_min)
+{
+	if (actual_maj > target_maj)
+		return 1;
+
+	if (actual_maj == target_maj && actual_min >= target_min)
+		return 1;
+
+	return 0;
+}
+
 static void _dm_set_crypt_compat(const char *dm_version, unsigned crypt_maj,
 				 unsigned crypt_min, unsigned crypt_patch)
 {
@@ -111,25 +123,25 @@ static void _dm_set_crypt_compat(const char *dm_version, unsigned crypt_maj,
 	log_dbg("Detected dm-crypt version %i.%i.%i, dm-ioctl version %u.%u.%u.",
 		crypt_maj, crypt_min, crypt_patch, dm_maj, dm_min, dm_patch);
 
-	if (crypt_maj >= 1 && crypt_min >= 2)
+	if (_dm_satisfies_version(1, 2, crypt_maj, crypt_min))
 		_dm_crypt_flags |= DM_KEY_WIPE_SUPPORTED;
 	else
 		log_dbg("Suspend and resume disabled, no wipe key support.");
 
-	if (crypt_maj >= 1 && crypt_min >= 10)
+	if (_dm_satisfies_version(1, 10, crypt_maj, crypt_min))
 		_dm_crypt_flags |= DM_LMK_SUPPORTED;
 
-	if (dm_maj >= 4 && dm_min >= 20)
+	if (_dm_satisfies_version(4, 20, dm_maj, dm_min))
 		_dm_crypt_flags |= DM_SECURE_SUPPORTED;
 
 	/* not perfect, 2.6.33 supports with 1.7.0 */
-	if (crypt_maj >= 1 && crypt_min >= 8)
+	if (_dm_satisfies_version(1, 8, crypt_maj, crypt_min))
 		_dm_crypt_flags |= DM_PLAIN64_SUPPORTED;
 
-	if (crypt_maj >= 1 && crypt_min >= 11)
+	if (_dm_satisfies_version(1, 11, crypt_maj, crypt_min))
 		_dm_crypt_flags |= DM_DISCARDS_SUPPORTED;
 
-	if (crypt_maj >= 1 && crypt_min >= 13)
+	if (_dm_satisfies_version(1, 13, crypt_maj, crypt_min))
 		_dm_crypt_flags |= DM_TCW_SUPPORTED;
 
 	/* Repeat test if dm-crypt is not present */
-- 
1.8.4.2

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [dm-crypt] [PATCH] libdevmapper: correctly compare major and minor versions
  2013-11-13 21:27 [dm-crypt] [PATCH] libdevmapper: correctly compare major and minor versions Dave Reisner
@ 2013-11-14  7:38 ` Milan Broz
  0 siblings, 0 replies; 2+ messages in thread
From: Milan Broz @ 2013-11-14  7:38 UTC (permalink / raw)
  To: Dave Reisner; +Cc: dm-crypt

On 11/13/2013 10:27 PM, Dave Reisner wrote:
> Previously, this code could incorrectly identify a version of crypt or
> dm due to the way it compared versions. For example, if a feature was
> gated on crypt version 1.5, it would disable the feature for crypt
> version 2.2.

Yes, intention was just simple version check. Anyway, in most cases
code tries use feature, and only if it fails, it reports error
about missing support (this should prevent issues on some systems
with backported patches without module version changes).

Anyway, patch applied, thanks!

Milan

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-11-14  7:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-13 21:27 [dm-crypt] [PATCH] libdevmapper: correctly compare major and minor versions Dave Reisner
2013-11-14  7:38 ` Milan Broz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.