Skip to contentSkip to conversation

Fix: Filter ABI changes to support FILTER_BYTECODE_MAX_LEN (65536)

PATCH Superseded Mathieu Desnoyers 2 participants 6 messages Sep 5, 2012 – Sep 6, 2012 4 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 25 lines · * Christian Babeux ([email protected]) wrote:

In order to support the filter bytecode maximum length (65536 bytes), the lttng_ust_filter_bytecode len field type must be able to hold more than a uint16_t. Change the field type to a uint32_t.

Also, since the relocation table is located at the end of the actual bytecode, the reloc_offset field must support offset values larger than 65535. Change the field type to a uint32_t. This change will allow support of relocation table appended to larger bytecode without breaking the ABI if the need arise in the future.

Both changes currently breaks the filter ABI, but this should be a reasonable compromise since the filtering feature has not been released yet.

---
 include/lttng/ust-abi.h | 4 ++--
 include/ust-comm.h      | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
include/lttng/ust-abi.h +0 -0
index 0489e89..91639a7 100644

include/lttng/ust-abi.h struct lttng_ust_calibrate { · line 178

Quoted 7 lines
include/lttng/ust-abi.h +2 -2
@@ -174,8 +174,8 @@ struct lttng_ust_calibrate {
 
 #define FILTER_BYTECODE_MAX_LEN		65536
 struct lttng_ust_filter_bytecode {
-	uint16_t len;
-	uint16_t reloc_offset;
+	uint32_t len;
+	uint32_t reloc_offset;

You'll need to add a check in liblttng-ust/lttng-ust-comm.c, when the data is received: we need to check that the reloc_offset is within the data.

Mathieu

Quoted 21 lines
include/lttng/ust-abi.h +0 -0
 	char data[0];
 };
 
include/ust-comm.h +2 -2
index b09fcca..4a3e4ce 100644
@@ -132,8 +132,8 @@ struct ustcomm_ust_msg {
 		struct lttng_ust_tracer_version version;
 		struct lttng_ust_tracepoint_iter tracepoint;
 		struct {
-			uint16_t data_size;	/* following filter data */
-			uint16_t reloc_offset;
+			uint32_t data_size;	/* following filter data */
+			uint32_t reloc_offset;
 		} filter;
 	} u;
 };
Signature · 1 line
1.7.11.4
Signature · 4 lines
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
#2 lore raw

PATCH v2 1/1 Fix: Filter ABI changes to support FILTER_BYTECODE_MAX_LEN (65536)

In reply to a message not in the archive

v2 Changelog:
- Add a check when receiving data on the reloc_offset to ensure it lies within the data.

Christian Babeux (1):
Fix: Accept bytecode of length 65536 bytes

 include/lttng/ust-abi.h       | 4 ++--
 include/ust-comm.h            | 4 ++--
 liblttng-ust/lttng-ust-comm.c | 8 ++++++++
 3 files changed, 12 insertions(+), 4 deletions(-)
Signature · 1 line
1.7.11.4

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

PATCH v2 1/1 Fix: Accept bytecode of length 65536 bytes

In order to support the filter bytecode maximum length (65536 bytes), the lttng_ust_filter_bytecode len field type must be able to hold more than a uint16_t. Change the field type to a uint32_t.

Also, since the relocation table is located at the end of the actual bytecode, the reloc_table_offset (reloc_offset in ust-abi) field must support offset values larger than 65535. Change the field type to a uint32_t. This change will allow support of relocation table appended to larger bytecode without breaking the ABI if the need arise in the future.

Both changes currently breaks the filter ABI, but this should be a reasonable compromise since the filtering feature has not been released yet.

---
 include/lttng/ust-abi.h       | 4 ++--
 include/ust-comm.h            | 4 ++--
 liblttng-ust/lttng-ust-comm.c | 8 ++++++++
 3 files changed, 12 insertions(+), 4 deletions(-)
include/lttng/ust-abi.h +2 -2
index 0489e89..91639a7 100644
@@ -174,8 +174,8 @@ struct lttng_ust_calibrate {
 
 #define FILTER_BYTECODE_MAX_LEN		65536
 struct lttng_ust_filter_bytecode {
-	uint16_t len;
-	uint16_t reloc_offset;
+	uint32_t len;
+	uint32_t reloc_offset;
 	char data[0];
 };
 
include/ust-comm.h +2 -2
index b09fcca..4a3e4ce 100644
@@ -132,8 +132,8 @@ struct ustcomm_ust_msg {
 		struct lttng_ust_tracer_version version;
 		struct lttng_ust_tracepoint_iter tracepoint;
 		struct {
-			uint16_t data_size;	/* following filter data */
-			uint16_t reloc_offset;
+			uint32_t data_size;	/* following filter data */
+			uint32_t reloc_offset;
 		} filter;
 	} u;
 };
liblttng-ust/lttng-ust-comm.c +8 -0
index 842876f..009dc02 100644
@@ -293,6 +293,14 @@ int handle_message(struct sock_info *sock_info,
 			ret = -EINVAL;
 			goto error;
 		}
+
+		if (lum->u.filter.reloc_offset > lum->u.filter.data_size) {
+			ERR("Filter reloc offset %u is not within data\n",
+				lum->u.filter.reloc_offset);
+			ret = -EINVAL;
+			goto error;
+		}
+
 		bytecode = zmalloc(sizeof(*bytecode) + lum->u.filter.data_size);
 		if (!bytecode) {
 			ret = -ENOMEM;
Signature · 1 line
1.7.11.4

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

Re: [PATCH v2 lttng-ust] Fix: Accept bytecode of length 65536 bytes

Quoted 57 lines · * Christian Babeux ([email protected]) wrote:

In order to support the filter bytecode maximum length (65536 bytes), the lttng_ust_filter_bytecode len field type must be able to hold more than a uint16_t. Change the field type to a uint32_t.

Also, since the relocation table is located at the end of the actual bytecode, the reloc_table_offset (reloc_offset in ust-abi) field must support offset values larger than 65535. Change the field type to a uint32_t. This change will allow support of relocation table appended to larger bytecode without breaking the ABI if the need arise in the future.

Both changes currently breaks the filter ABI, but this should be a reasonable compromise since the filtering feature has not been released yet.

---
 include/lttng/ust-abi.h       | 4 ++--
 include/ust-comm.h            | 4 ++--
 liblttng-ust/lttng-ust-comm.c | 8 ++++++++
 3 files changed, 12 insertions(+), 4 deletions(-)
include/lttng/ust-abi.h +2 -2
index 0489e89..91639a7 100644
@@ -174,8 +174,8 @@ struct lttng_ust_calibrate {
 
 #define FILTER_BYTECODE_MAX_LEN		65536
 struct lttng_ust_filter_bytecode {
-	uint16_t len;
-	uint16_t reloc_offset;
+	uint32_t len;
+	uint32_t reloc_offset;
 	char data[0];
 };
 
include/ust-comm.h +2 -2
index b09fcca..4a3e4ce 100644
@@ -132,8 +132,8 @@ struct ustcomm_ust_msg {
 		struct lttng_ust_tracer_version version;
 		struct lttng_ust_tracepoint_iter tracepoint;
 		struct {
-			uint16_t data_size;	/* following filter data */
-			uint16_t reloc_offset;
+			uint32_t data_size;	/* following filter data */
+			uint32_t reloc_offset;
 		} filter;
 	} u;
 };
liblttng-ust/lttng-ust-comm.c +0 -0
index 842876f..009dc02 100644

liblttng-ust/lttng-ust-comm.c int handle_message(struct sock_info *sock_info, · line 297

Quoted 5 lines
liblttng-ust/lttng-ust-comm.c +2 -0
@@ -293,6 +293,14 @@ int handle_message(struct sock_info *sock_info,
 			ret = -EINVAL;
 			goto error;
 		}
+
+		if (lum->u.filter.reloc_offset > lum->u.filter.data_size) {

if (lum->u.filter.reloc_offset > lum->u.filter.data_size - 1) {

?

Quoted 12 lines
liblttng-ust/lttng-ust-comm.c +6 -0
+			ERR("Filter reloc offset %u is not within data\n",
+				lum->u.filter.reloc_offset);
+			ret = -EINVAL;
+			goto error;
+		}
+
 		bytecode = zmalloc(sizeof(*bytecode) + lum->u.filter.data_size);
 		if (!bytecode) {
 			ret = -ENOMEM;
Signature · 1 line
1.7.11.4
Signature · 4 lines
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
#7 lore raw

PATCH v3 1/1 Fix: Filter ABI changes to support FILTER_BYTECODE_MAX_LEN (65536)

In reply to a message not in the archive

In order to support the filter bytecode maximum length (65536 bytes), the lttng_ust_filter_bytecode len field type must be able to hold more than a uint16_t. Change the field type to a uint32_t.

Also, since the relocation table is located at the end of the actual bytecode, the reloc_table_offset (reloc_offset in ust-abi) field must support offset values larger than 65535. Change the field type to a uint32_t. This change will allow support of relocation table appended to larger bytecode without breaking the ABI if the need arise in the future.

Both changes currently breaks the filter ABI, but this should be a reasonable compromise since the filtering feature has not been released yet.

---
 include/lttng/ust-abi.h       | 4 ++--
 include/ust-comm.h            | 4 ++--
 liblttng-ust/lttng-ust-comm.c | 8 ++++++++
 3 files changed, 12 insertions(+), 4 deletions(-)
include/lttng/ust-abi.h +2 -2
index 0489e89..91639a7 100644
@@ -174,8 +174,8 @@ struct lttng_ust_calibrate {
 
 #define FILTER_BYTECODE_MAX_LEN		65536
 struct lttng_ust_filter_bytecode {
-	uint16_t len;
-	uint16_t reloc_offset;
+	uint32_t len;
+	uint32_t reloc_offset;
 	char data[0];
 };
 
include/ust-comm.h +2 -2
index b09fcca..4a3e4ce 100644
@@ -132,8 +132,8 @@ struct ustcomm_ust_msg {
 		struct lttng_ust_tracer_version version;
 		struct lttng_ust_tracepoint_iter tracepoint;
 		struct {
-			uint16_t data_size;	/* following filter data */
-			uint16_t reloc_offset;
+			uint32_t data_size;	/* following filter data */
+			uint32_t reloc_offset;
 		} filter;
 	} u;
 };
liblttng-ust/lttng-ust-comm.c +8 -0
index 842876f..be64acd 100644
@@ -293,6 +293,14 @@ int handle_message(struct sock_info *sock_info,
 			ret = -EINVAL;
 			goto error;
 		}
+
+		if (lum->u.filter.reloc_offset > lum->u.filter.data_size - 1) {
+			ERR("Filter reloc offset %u is not within data\n",
+				lum->u.filter.reloc_offset);
+			ret = -EINVAL;
+			goto error;
+		}
+
 		bytecode = zmalloc(sizeof(*bytecode) + lum->u.filter.data_size);
 		if (!bytecode) {
 			ret = -ENOMEM;
Signature · 1 line
1.7.11.4

A message that is not in the archive (sent off-list or not yet received): [email protected]

author Applied
#9 lore raw
Quoted 11 lines · * Christian Babeux ([email protected]) wrote:

In order to support the filter bytecode maximum length (65536 bytes), the lttng_ust_filter_bytecode len field type must be able to hold more than a uint16_t. Change the field type to a uint32_t.

Also, since the relocation table is located at the end of the actual bytecode, the reloc_table_offset (reloc_offset in ust-abi) field must support offset values larger than 65535. Change the field type to a uint32_t. This change will allow support of relocation table appended to larger bytecode without breaking the ABI if the need arise in the future.

Quoted 3 lines

Both changes currently breaks the filter ABI, but this should be a reasonable compromise since the filtering feature has not been released yet.

merged, thanks!

Quoted 60 lines
---
 include/lttng/ust-abi.h       | 4 ++--
 include/ust-comm.h            | 4 ++--
 liblttng-ust/lttng-ust-comm.c | 8 ++++++++
 3 files changed, 12 insertions(+), 4 deletions(-)
include/lttng/ust-abi.h +2 -2
index 0489e89..91639a7 100644
@@ -174,8 +174,8 @@ struct lttng_ust_calibrate {
 
 #define FILTER_BYTECODE_MAX_LEN		65536
 struct lttng_ust_filter_bytecode {
-	uint16_t len;
-	uint16_t reloc_offset;
+	uint32_t len;
+	uint32_t reloc_offset;
 	char data[0];
 };
 
include/ust-comm.h +2 -2
index b09fcca..4a3e4ce 100644
@@ -132,8 +132,8 @@ struct ustcomm_ust_msg {
 		struct lttng_ust_tracer_version version;
 		struct lttng_ust_tracepoint_iter tracepoint;
 		struct {
-			uint16_t data_size;	/* following filter data */
-			uint16_t reloc_offset;
+			uint32_t data_size;	/* following filter data */
+			uint32_t reloc_offset;
 		} filter;
 	} u;
 };
liblttng-ust/lttng-ust-comm.c +8 -0
index 842876f..be64acd 100644
@@ -293,6 +293,14 @@ int handle_message(struct sock_info *sock_info,
 			ret = -EINVAL;
 			goto error;
 		}
+
+		if (lum->u.filter.reloc_offset > lum->u.filter.data_size - 1) {
+			ERR("Filter reloc offset %u is not within data\n",
+				lum->u.filter.reloc_offset);
+			ret = -EINVAL;
+			goto error;
+		}
+
 		bytecode = zmalloc(sizeof(*bytecode) + lum->u.filter.data_size);
 		if (!bytecode) {
 			ret = -ENOMEM;
Signature · 1 line
1.7.11.4
Signature · 4 lines
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com