Răsfoiți Sursa

schedwrk: Cleanup and make it work on PPC BE

Schedwrk is passing hdb handle (64-bit) to
totempg_callback_token_create as a context. Context is defined to be
pointer, so there is conversion function which stores 64-bit hdb_handle
into pointer. Potentially, pointer can be 32-bit. This means, check
part of hdb is discarded (and have to get special no_check value in
schedwrk_do) later. This works quite well on 32-bit Little-Endian
system. Sadly on Big-Endian system, check partition of hdb is stored
instead of value. Result is error of hdb_handle_get call.

Proposed solution is to pass handle pointer to
totempg_callback_token_create as context. This means full hdb (check +
value) can be used in schedwrk_do (easier detection of memory
corruption).

Main reason for this patch is to remove usage of pointer as integer
value.

Small drawback of given solution is that handle pointer must be memory
allocated on heap or static memory, making API more bug-prone. Current
usage of schedwrk API across corosync always use memory in .text
section (safe), so it's not a problem.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Christine Caulfield <ccaulfie@redhat.com>
Jan Friesse 9 ani în urmă
părinte
comite
b93d75abc4
1 a modificat fișierele cu 10 adăugiri și 15 ștergeri
  1. 10 15
      exec/schedwrk.c

+ 10 - 15
exec/schedwrk.c

@@ -49,23 +49,14 @@ struct schedwrk_instance {
 	int lock;
 };
 
-union u {
-  hdb_handle_t h;
-  const void *v;
-};
-static hdb_handle_t
-void2handle (const void *v) { union u u; u.v = v; return u.h; }
-static const void *
-handle2void (hdb_handle_t h) { union u u; u.h = h; return u.v; }
-
 static int schedwrk_do (enum totem_callback_token_type type, const void *context)
 {
-	hdb_handle_t handle = void2handle (context);
+	hdb_handle_t handle = *((hdb_handle_t *)context);
 	struct schedwrk_instance *instance;
 	int res;
 
 	res = hdb_handle_get (&schedwrk_instance_database,
-		hdb_nocheck_convert (handle),
+		handle,
 		(void *)&instance);
 	if (res != 0) {
 		goto error_exit;
@@ -80,10 +71,9 @@ static int schedwrk_do (enum totem_callback_token_type type, const void *context
 		serialize_unlock ();
 
 	if (res == 0) {
-		hdb_handle_destroy (&schedwrk_instance_database, hdb_nocheck_convert (handle));
+		hdb_handle_destroy (&schedwrk_instance_database, handle);
 	}
-        hdb_handle_put (&schedwrk_instance_database,
-		hdb_nocheck_convert (handle));
+        hdb_handle_put (&schedwrk_instance_database, handle);
 	return (res);
 
 error_exit:
@@ -123,7 +113,7 @@ static int schedwrk_internal_create (
 		TOTEM_CALLBACK_TOKEN_SENT,
 		1,
 		schedwrk_do,
-		handle2void (*handle));
+		handle);
 
 	instance->schedwrk_fn = schedwrk_fn;
 	instance->context = context;
@@ -140,6 +130,11 @@ error_exit:
 	return (-1);
 }
 
+/*
+ * handle pointer is internally used by totempg_callback_token_create. To make schedwrk work,
+ * handle must be pointer to ether heap or .text or static memory (not stack) which is not
+ * changed by caller.
+ */
 int schedwrk_create (
 	hdb_handle_t *handle,
 	int (schedwrk_fn) (const void *),