From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id y/VPOkn1NmjfwDcAWB0awg (envelope-from ) for ; Wed, 28 May 2025 07:36:41 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=syntacore.com header.i=@syntacore.com header.a=rsa-sha256 header.s=m header.b=CpjbDry+; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id D36741E102; Wed, 28 May 2025 07:36:41 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-9.1 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL, RCVD_IN_VALIDITY_SAFE autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id D35EF1E102 for ; Wed, 28 May 2025 07:36:40 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9180C38515E5 for ; Wed, 28 May 2025 11:36:39 +0000 (GMT) Received: from m.syntacore.com (m.syntacore.com [178.249.69.228]) by sourceware.org (Postfix) with ESMTPS id B79443858D32 for ; Wed, 28 May 2025 11:36:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B79443858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=syntacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=syntacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B79443858D32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=178.249.69.228 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1748432170; cv=none; b=ZPTDErOPNpYC3AVwwiHlbluaIadvEJCCe1PcNbHPWQbsk+gJrjlZO4b/zFiFqC5uYaVJSu0fgA++NiDiB8OwcoEEc0h7Hf7vBamLK0rYlSlvkTWBKdzHMS1syY02qSnZtgFgMVjPoN2MBSnXMerngz1kxcuiN6DasA5BJ0atsh4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1748432170; c=relaxed/simple; bh=GBi2Wiu5qThct+lV1VuMmWpq+qsYDi+LNWGcg9jCuZ0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Lxi9ypjFaC0I41UeIq3xtaodfYX3tNp9AQFkuuZc7hN5caRpYLS7Ga3QhXZ3auWK0BfAviNtkYyieDf+Txmzk9/Gd0lmfAtJ77ElKdyK+64tfzgIl5w5QZdvAAbFBwo1C6SeadkMw5OMyWVfQHcLT5+ce5nif77z/9ZMKeO51W0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from MRN-SC-KSMG-01.corp.syntacore.com (localhost [127.0.0.1]) by m.syntacore.com (Postfix) with ESMTP id 27F5A1A0002 for ; Wed, 28 May 2025 11:35:39 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 m.syntacore.com 27F5A1A0002 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syntacore.com; s=m; t=1748432139; bh=KiTVYqkvIKQtTQc1QISnwq7TwV/ccFtVYK6I84GJSWM=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=CpjbDry+D7ySQx6wnyu4iqWNjKngnDQ74cQEo3jW+V6g4H887cDM7TM0aPeENLHlf ppxcyghFSdKYQ5OKtf5o/5p/kTkpxQNbqjayzCMN0n8cNwJObxd+cxEl7WJ035aC7r f97wOW2tEaxjE8ukb7q51VmgpElmWRhEZMmEbvLfHqUL4I6PdDRr0fiCSM4Z58LNah ht0LjGDXHC9bRfyQ+bgcypopG5Ibb7qHbyWyPVEtot/0fcCP1NbC0/WamSxWmG5D10 30kEd6Si3NiDXW3qEE4bmw5HIjIzP7vgPC8X2E3I8YqNLM/Tjg6qcg1jRPidrzrcXn QXuTYjcn8N+7w== Received: from S-SC-EXCH-01.corp.syntacore.com (exchange.syntacore.com [10.76.202.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by m.syntacore.com (Postfix) with ESMTPS for ; Wed, 28 May 2025 11:35:38 +0000 (UTC) Received: from kr-sc-ThinkPad-E14-Gen-2.corp.yadro.com (10.178.146.83) by S-SC-EXCH-01.corp.syntacore.com (10.76.202.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 28 May 2025 14:34:35 +0300 From: Kirill Radkin To: CC: Subject: [PATCH] gdbserver: Update require_int function to parse offset for pread packet Date: Wed, 28 May 2025 14:35:13 +0300 Message-ID: <20250528113513.3116529-1-kirill.radkin@syntacore.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250423161548.03f50c47@f41-zbm-amd> References: <20250423161548.03f50c47@f41-zbm-amd> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.178.146.83] X-ClientProxiedBy: S-SC-EXCH-01.corp.syntacore.com (10.76.202.20) To S-SC-EXCH-01.corp.syntacore.com (10.76.202.20) X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.1.1.8310, bases: 2025/05/28 10:03:00 #27564739 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: NotDetected, bases: 2025/05/28 11:25:00 X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 5 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Currently gdbserver uses require_int() function to parse the requested offset (in vFile::pread packet and the like). This function allows integers up to 0x7fffffff (to fit in 32-bit int), however the offset (for pread system call) has an off_t type which can be larger than 32-bit. This patch allows require_int() function to parse offset up to the maximum value implied by the off_t type. --- gdb/testsuite/gdb.server/pread-offset-size.S | 26 +++++++++++ .../gdb.server/pread-offset-size.exp | 45 +++++++++++++++++++ gdbserver/hostio.cc | 18 +++++--- 3 files changed, 84 insertions(+), 5 deletions(-) create mode 100644 gdb/testsuite/gdb.server/pread-offset-size.S create mode 100644 gdb/testsuite/gdb.server/pread-offset-size.exp diff --git a/gdb/testsuite/gdb.server/pread-offset-size.S b/gdb/testsuite/gdb.server/pread-offset-size.S new file mode 100644 index 00000000000..f43e059653d --- /dev/null +++ b/gdb/testsuite/gdb.server/pread-offset-size.S @@ -0,0 +1,26 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2025 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + + .text + .globl _start +_start: + .skip 3742415472 + ret + .globl f + .type f, @function +f: + ret diff --git a/gdb/testsuite/gdb.server/pread-offset-size.exp b/gdb/testsuite/gdb.server/pread-offset-size.exp new file mode 100644 index 00000000000..5faf2162ef0 --- /dev/null +++ b/gdb/testsuite/gdb.server/pread-offset-size.exp @@ -0,0 +1,45 @@ +# Copyright (C) 2025 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +load_lib gdbserver-support.exp + +require allow_gdbserver_tests + +standard_testfile .S + +if { [prepare_for_testing ${testfile}.exp $testfile \ + $srcfile {debug additional_flags=-nostdlib} ] } { + return -1 +} + +gdb_exit +gdb_start + +gdb_test_no_output "set remote exec-file $binfile" \ +"set remote exec-file" + +# Make sure we're disconnected, in case we're testing with an +# extended-remote board, therefore already connected. +gdb_test "disconnect" ".*" + +set res [gdbserver_spawn ""] +set gdbserver_protocol [lindex $res 0] +set gdbserver_gdbport [lindex $res 1] + +gdb_test "target $gdbserver_protocol $gdbserver_gdbport" \ +"Remote debugging using .*" \ +"target $gdbserver_protocol $gdbserver_gdbport" + +gdb_test "break f" "Breakpoint 1.*" diff --git a/gdbserver/hostio.cc b/gdbserver/hostio.cc index 17b6179d8ca..e88f8d79728 100644 --- a/gdbserver/hostio.cc +++ b/gdbserver/hostio.cc @@ -89,12 +89,18 @@ require_filename (char **pp, char *filename) return 0; } +template static int -require_int (char **pp, int *value) +require_int (char **pp, T *value) { + constexpr bool is_signed = std::is_signed::value; + char *p; int count, firstdigit; + /* Max count of hexadecimal digits in off_t (1 hex digit is 4 bits). */ + int max_count = sizeof(T) * CHAR_BIT / 4; + p = *pp; *value = 0; count = 0; @@ -111,9 +117,9 @@ require_int (char **pp, int *value) firstdigit = nib; /* Don't allow overflow. */ - if (count >= 8 || (count == 7 && firstdigit >= 0x8)) + if (count >= max_count + || (is_signed && count == (max_count - 1) && firstdigit >= 0x8)) return -1; - *value = *value * 16 + nib; p++; count++; @@ -343,7 +349,8 @@ handle_open (char *own_buf) static void handle_pread (char *own_buf, int *new_packet_len) { - int fd, ret, len, offset, bytes_sent; + int fd, ret, len, bytes_sent; + off_t offset; char *p, *data; static int max_reply_size = -1; @@ -410,7 +417,8 @@ handle_pread (char *own_buf, int *new_packet_len) static void handle_pwrite (char *own_buf, int packet_len) { - int fd, ret, len, offset; + int fd, ret, len; + off_t offset; char *p, *data; p = own_buf + strlen ("vFile:pwrite:"); -- 2.43.0