net/tls: Fix to avoid gettig invalid tls record
Subsystems (4)
Current code doesn't check if tcp sequence number is starting from (/after) 1st record's start sequnce number. It only checks if seq number is before 1st record's end sequnce number. This problem will always be a possibility in re-transmit case. If a record which belongs to a requested seq number is already deleted, tls_get_record will start looking into list and as per the check it will look if seq number is before the end seq of 1st record, which will always be true and will return 1st record always, it should in fact return NULL.
--- net/tls/tls_device.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/tls/tls_device.c +2 -1
@@ -602,7 +602,8 @@ struct tls_record_info *tls_get_record(struct tls_offload_context_tx *context,*/ info =list_first_entry_or_null (&context->records_list, struct tls_record_info, list); -if (!info) +/* return NULL if seq number even before the 1st entry. */ +if (!info ||before (seq, info->end_seq - info->len))return NULL ; record_sn = context->unacked_record_sn; }
Signature · 1 line
2.25.0.191.gde93cc1
Jakub Kicinski
maintainerQuoted 8 lines · Rohit Maheshwari
Current code doesn't check if tcp sequence number is starting from (/after) 1st record's start sequnce number. It only checks if seq number is before 1st record's end sequnce number. This problem will always be a possibility in re-transmit case. If a record which belongs to a requested seq number is already deleted,
tls_get_recordwill start looking into list and as per the check it will look if seq number is before the end seq of 1st record, which will always be true and will return 1st record always, it should in fact return NULL.
I think I see your point, do you observe this problem in practice or did you find this through code review?
net/tls/tls_device.c struct tls_record_info *tls_get_record(struct tls_offload_context_tx *context, · line 606
Quoted 11 lines
net/tls/tls_device.c +2
-1@@ -602,7 +602,8 @@ struct tls_record_info *tls_get_record(struct tls_offload_context_tx *context,*/ info =list_first_entry_or_null (&context->records_list, struct tls_record_info, list); -if (!info) +/* return NULL if seq number even before the 1st entry. */ +if (!info ||before (seq, info->end_seq - info->len))
Is it not more appropriate to use between() in the actual comparison below? I feel like with this patch we can get false negatives.
net/tls/tls_device.c struct tls_record_info *tls_get_record(struct tls_offload_context_tx *context, · line 609
Quoted 3 lines
net/tls/tls_device.c +0
-0return NULL ; record_sn = context->unacked_record_sn; }
If you post a v2 please add a Fixes tag and CC maintainers of this code.
Quoted 11 lines · Jakub Kicinski
Quoted 8 lines · Rohit Maheshwari
Current code doesn't check if tcp sequence number is starting from (/after) 1st record's start sequnce number. It only checks if seq number is before 1st record's end sequnce number. This problem will always be a possibility in re-transmit case. If a record which belongs to a requested seq number is already deleted,
tls_get_recordwill start looking into list and as per the check it will look if seq number is before the end seq of 1st record, which will always be true and will return 1st record always, it should in fact return NULL.I think I see your point, do you observe this problem in practice or did you find this through code review?
I am seeing this issue while running stress test.
Quoted 5 lines
Quoted 5 lines
net/tls/tls_device.c +0
-0@@ -602,7 +602,8 @@ struct tls_record_info *tls_get_record(struct tls_offload_context_tx *context,
Quoted 8 lines
net/tls/tls_device.c struct tls_record_info *tls_get_record(struct tls_offload_context_tx *context, · line 606
Quoted 6 lines
net/tls/tls_device.c +2
-1*/ info =list_first_entry_or_null (&context->records_list, struct tls_record_info, list); -if (!info) +/* return NULL if seq number even before the 1st entry. */ +if (!info ||before (seq, info->end_seq - info->len))Is it not more appropriate to use
between()in the actual comparison below? I feel like with this patch we can get false negatives.
If we use between(), though record doesn't exist, we still go and compare each record,
which I think, should actually be avoided.
Quoted 4 lines
net/tls/tls_device.c struct tls_record_info *tls_get_record(struct tls_offload_context_tx *context, · line 609
Quoted 3 lines
net/tls/tls_device.c +0
-0return NULL ; record_sn = context->unacked_record_sn; }If you post a v2 please add a Fixes tag and CC maintainers of this code.
Jakub Kicinski
maintainerQuoted 18 lines · On Thu, 13 Feb 2020 12:25:36 +0530 rohit maheshwari wrote:
Quoted 8 lines · Jakub Kicinski
Quoted 8 lines
net/tls/tls_device.c +0
-0@@ -602,7 +602,8 @@ struct tls_record_info *tls_get_record(struct
tls_offload_context_tx*context, */
info =
list_first_entry_or_null(&context->records_list, structQuoted 8 lines
Quoted 6 lines
tls_record_info, list);net/tls/tls_device.c +1
-1-if (!info) +/* return NULL if seq number even before the 1st entry. */
net/tls/tls_device.c +1
-0+ if (!info || before(seq, info->end_seq -
info->len))Is it not more appropriate to use
between()in the actual comparison below? I feel like with this patch we can get false negatives.
Quoted 4 lines
If we use
between(), though record doesn't exist, we still go and compare each record,which I think, should actually be avoided.
You can between() first and last element on the list at the very start of the search.
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
return NULL; record_sn = context->unacked_record_sn; }If you post a v2 please add a Fixes tag and CC maintainers of this code.