DE10252347A1 - Subroutine execution monitoring method, stores subroutine return address in program stack then compares with address given by subroutine return command to determine if error has occurred - Google Patents

Subroutine execution monitoring method, stores subroutine return address in program stack then compares with address given by subroutine return command to determine if error has occurred Download PDF

Info

Publication number
DE10252347A1
DE10252347A1 DE2002152347 DE10252347A DE10252347A1 DE 10252347 A1 DE10252347 A1 DE 10252347A1 DE 2002152347 DE2002152347 DE 2002152347 DE 10252347 A DE10252347 A DE 10252347A DE 10252347 A1 DE10252347 A1 DE 10252347A1
Authority
DE
Germany
Prior art keywords
subroutine
address
return
stack
return command
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Ceased
Application number
DE2002152347
Other languages
German (de)
Inventor
Michael Baldischweiler
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Giesecke and Devrient GmbH
Original Assignee
Giesecke and Devrient GmbH
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Giesecke and Devrient GmbH filed Critical Giesecke and Devrient GmbH
Priority to DE2002152347 priority Critical patent/DE10252347A1/en
Publication of DE10252347A1 publication Critical patent/DE10252347A1/en
Ceased legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/362Software debugging
    • G06F11/3636Software debugging by tracing the execution of the program
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/50Monitoring users, programs or devices to maintain the integrity of platforms, e.g. of processors, firmware or operating systems
    • G06F21/52Monitoring users, programs or devices to maintain the integrity of platforms, e.g. of processors, firmware or operating systems during program execution, e.g. stack integrity ; Preventing unwanted data erasure; Buffer overflow
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/70Protecting specific internal or peripheral components, in which the protection of a component leads to protection of the entire computer
    • G06F21/71Protecting specific internal or peripheral components, in which the protection of a component leads to protection of the entire computer to assure secure computing or processing of information
    • G06F21/77Protecting specific internal or peripheral components, in which the protection of a component leads to protection of the entire computer to assure secure computing or processing of information in smart cards
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/30Arrangements for executing machine instructions, e.g. instruction decode
    • G06F9/38Concurrent instruction execution, e.g. pipeline or look ahead
    • G06F9/3802Instruction prefetching
    • G06F9/3804Instruction prefetching for branches, e.g. hedging, branch folding
    • G06F9/3806Instruction prefetching for branches, e.g. hedging, branch folding using address prediction, e.g. return stack, branch history buffer

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Hardware Design (AREA)
  • Computer Security & Cryptography (AREA)
  • Quality & Reliability (AREA)
  • Mathematical Physics (AREA)
  • Executing Machine-Instructions (AREA)

Abstract

When a subroutine is called (34) a return address (38) is stored in the program stack (30). When a subroutine return command (40) is executed the address in the return command and the address in the stack are compared to determine if they have a predetermined relationship to each other. If not, an error handling routine is called. Independent claims are also included for the following ; (1) processor; (2) chip card with processor.

Description

Die Erfindung betrifft allgemein das Gebiet der Prozessortechnik und insbesondere das Gebiet der überwachten Ausführung von Unterprogrammen. Speziell ist die Erfindung für Anwendungen vorgesehen, bei denen Aspekte der Sicherheit und Korrektheit der ausgeführten Programme sowie der Zuverlässigkeit der Programmausführung besondere Bedeutung haben.The invention relates generally the area of processor technology and in particular the area of monitored execution of subroutines. The invention is special for applications provided for aspects of security and correctness of the executed Programs as well as reliability the program execution have special meaning.

Techniken zur Ausführung von Unterprogrammen sind in vielfältigen Ausgestaltungen gut bekannt. So sind beispielsweise in dem Buch "MCS-48 Family of Single Chip Microcomputers User's Manual", herausgegeben von Intel Corporation, USA, September 1981, auf den Seiten 4-12 und 4-30 die Befehle CALL und RET der Mikrocontroller-Familie MCS-48 beschrieben. Gemäß diesem Stand der Technik wird bei der Ausführung eines Unterprogramm-Aufrufbefehls CALL unter anderem der aktuelle Stand des Programmzählers in einem Stapelspeicher gesichert. Die Programmausführung wird dann an einer in dem Unterprogramm-Aufrufbefehl angegebenen Adresse fortgesetzt. Sobald im Zuge der Unterprogrammausführung der erste Unterprogramm-Rücksprungbefehl RET erkannt wird, wird der Programmzähler mit dem jüngsten Eintrag im Stapelspeicher geladen. Dieser Eintrag wird aus dem Stapelspeicher entfernt, indem der Stapelzeiger entsprechend geändert, beispielsweise dekrementiert, wird. Die Wirkung des Unterprogramm-Rücksprungbefehls ist somit, daß die Programmausführung im aufrufenden Programm mit demjenigen Befehl fortgesetzt wird, der dem Unterprogramm-Aufrufbefehl folgt.Techniques for performing Subroutines are in diverse Configurations well known. For example, in the book "MCS-48 Family of Single Chip Microcomputers User's Manual " by Intel Corporation, USA, September 1981, pages 4-12 and 4-30 the CALL and RET commands of the MCS-48 microcontroller family described. According to this State of the art is when a subroutine call instruction CALL is executed among other things, the current status of the program counter in a stack secured. The program execution is then specified at one in the subroutine call instruction Address continued. As soon as the first subroutine return command RET is recognized, the program counter with the most recent entry loaded in the stack. This entry is from the stack removed by changing the stack pointer accordingly, e.g. decrementing it. The effect of the subroutine return instruction is therefore that the program execution is continued in the calling program with that command, which follows the subroutine call instruction.

Dieses bekannte Verfahren hat jedoch den Nachteil, daß die Zuordnung von Unterprogramm-Aufrufbefehlen und Unterprogramm-Rücksprungbefehlen lediglich gemäß der Reihenfolge erfolgt, in der diese Befehle während der Programmausführung angetroffen werden. Wenn daher der aktuelle Programmfluß von den Vorstellungen des Programmierers abweicht – dies kann beispielsweise durch einen Programmierfehler oder durch eine zur Programmlaufzeit auftretende Störung der Fall sein -, so gerät die Zuordnung von Unterprogramm-Aufrufen und Unterprogramm-Rücksprüngen völlig durcheinander. Gerade bei sicherheitskritischen Anwendungen können die dadurch hervorgerufenen Fehlfunktionen potenziell schwere Schäden verursachen.However, this known method has the disadvantage that the Assignment of subroutine call instructions and subroutine return instructions just according to the order done in which these commands during the program execution be encountered. Therefore, if the current program flow from the The programmer's ideas deviate - this can be caused, for example, by a programming error or one that occurs during the program runtime disorder be the case - so it gets the assignment of subroutine calls and subroutine returns completely mixed up. This can result in safety-critical applications Malfunctions can cause serious damage.

Die Erfindung hat daher die Aufgabe, die genannten Probleme zumindest zum Teil zu vermeiden. Insbesondere soll durch die Erfindung eine Technik zur überwachten Unterprogrammausführung bereitgestellt werden, welche eine fehlerhafte Programmierung oder Hardwarefehler während der Programmausführung zumindest mit gewisser Wahrscheinlichkeit erkennt und somit geeignete Gegenmaßnahmen ermöglicht.The invention therefore has the task to avoid the problems mentioned at least in part. In particular is intended to provide a technology for monitoring subroutine execution by the invention what a faulty programming or hardware failure while the program execution recognizes at least with a certain probability and thus suitable ones countermeasures allows.

Erfindungsgemäß wird diese Aufgabe ganz oder zum Teil gelöst durch ein Verfahren mit den Merkmalen von Anspruch 1, einen Prozessor gemäß Anspruch 9 und einen Datenträger gemäß Anspruch 10. Die abhängigen Ansprüche definieren bevorzugte Ausgestaltungen der Erfindung. Die Aufzählungsreihenfolge der Schritte in den Verfahrensansprüchen soll nicht als Einschränkung des Schutzbereichs verstanden werden. Es sind vielmehr Ausgestaltungen der Erfindung vorgesehen, bei denen diese Verfahrensschritte in anderer Reihenfolge oder ganz oder teilweise parallel oder ganz oder teilweise ineinander verzahnt (interleaved) ausgeführt werden.According to the invention, this task is complete or partially solved by a method having the features of claim 1, a processor according to claim 9 and a disk according to claim 10. The dependent Expectations define preferred embodiments of the invention. The enumeration order The steps in the procedural claims are not intended to limit the Protection area can be understood. Rather, they are configurations provided the invention, in which these method steps in different order or in whole or in part in parallel or in whole or partially interleaved.

Die Erfindung geht von der Grundidee aus, während des Programmablaufs zumindest eine Plausibilitätsüberprüfung hinsichtlich der Zuordnung eines auszuführenden Unterprogramm-Rücksprungbefehls zu dein vom Programmierer vorgesehenen Aufrufbefehl vorzunehmen. Dazu wird beim Aufruf eines Unterprogramms nicht nur die Rücksprung-Zieladresse, sondern auch eine Rücksprungbefehlsadresse im Stapelspeicher abgelegt. Aus der Rücksprungbefehlsadresse läßt sich durch Auswerten einer vorgegebenen Beziehung ableiten, an welcher Stelle gemäß der Intention des Programmierers der zu dem gegenwärtig ausgeführten Unterprogramm-Aufrufbefehl gehörige Unterprogramm-Rücksprungbefehl bei korrekter Programmausführung zu erwarten ist. Beide genannten Adressen werden im Stapelspeicher abgelegt. Bei der Abarbeitung jedes Unterprogramm-Rücksprungbefehls wird überprüft, ob die Speicheradresse dieses Befehls in der vorgegebenen Beziehung zu der im Stapelspeicher befindlichen Rücksprungbefehlsadresse steht. Falls dies der Fall ist, war die Plausibilitätsüberprüfung erfolgreich, und der Rücksprung vom Unterprogramm wird ausgeführt. Andernfalls wird eine Fehlerbehandlungsroutine aufgerufen.The invention is based on the basic idea off while of the program sequence at least one plausibility check with regard to the assignment one to be executed Subroutine return instruction to carry out the call command provided by the programmer. When calling a subroutine, not only the return destination address, but also a return instruction address stored in the stack. From the return command address can be derive at which point by evaluating a predetermined relationship according to the intention the programmer to the subroutine call instruction currently being executed associated Subroutine return instruction with correct program execution is to be expected. Both of these addresses are in the stack stored. When processing each subroutine return instruction it is checked whether the Memory address of this command in the specified relationship to the return instruction address in the stack. If this is the case, the plausibility check was successful and the return is executed by the subroutine. Otherwise an error handling routine is called.

Durch die erfindungsgemäße Plausibilitätsüberprüfung können mit geringem Aufwand sowohl Programmierfehler als auch Programmablauffehler mit beträchtlicher Wahrscheinlichkeit erkannt werden. Dies ist insbesondere für sicherheitskritische Anwendungen von großer Bedeutung. Durch die Erfindung wird das Auftreten einer Klasse von Fehlern erkannt, die den vorgesehenen Programmablauf völlig verändern können und die deshalb besonders kritisch sind. Insgesamt ermöglicht die Erfindung eine Überwachung der dynamischen Ablaufstruktur des Programms unter Verwendung von Informationen, die sich auf die statische Programmstruktur beziehen.Through the plausibility check according to the invention, with low effort with programming errors as well as program sequence errors considerable Probability are recognized. This is particularly important for safety-critical applications of great Importance. The occurrence of a class of Errors recognized that can completely change the intended program sequence and which are therefore particularly critical. Overall, the Invention a surveillance the dynamic flow structure of the program using Information related to the static program structure.

Erfindungsgemäß wird das Bestehen einer vorgegebenen Beziehung zwischen der Adresse des gerade ausgeführten Unterprogramm-Rücksprungbefehls und der im Stapelspeicher vorhandenen Rücksprungbefehlsadresse überprüft. Diese vorgegebene Beziehung kann insbesondere die Identität sein. In anderen Ausgestaltungen ist die vorgegebene Beziehung, daß sich die beiden genannten Adressen um einen vorbestimmten, konstanten Versatz (offset) – z.B. um die Länge des Unterprogramm-Rücksprungbefehls – voneinander unterscheiden. Durch diese Konvention kann der hardwaremäßige Aufbau des Prozessors vereinfacht werden.According to the invention, the existence of a predetermined relationship is checked between the address of the subroutine return instruction which has just been executed and the return instruction address which is present in the stack. This predefined relationship can in particular be identity. In other configurations, the predetermined relationship is that the two addresses mentioned are a predetermined, constant offset (offset) - for example, by the length of the subroutine return instruction. The hardware structure of the processor can be simplified by this convention.

In bevorzugten Ausgestaltungen wird die Fehlerbehandlungsroutine durch einen Unterbrechungsmechanismus aufgerufen. Dies kann beispielsweise eine hardwaremäßig veranlaßte Unterbrechung (interrupt) sein, insbesondere eine nicht-maskierbare Unterbrechung (non-maskable interrupt – NMI).In preferred configurations the error handling routine through an interrupt mechanism called. This can be, for example, a hardware-induced interruption (interrupt), in particular a non-maskable interrupt (non-maskable interrupt - NMI).

In manchen Ausgestaltungen der Erfindung findet die genannte Plausibilitätsüberprüfung lediglich bei der Verarbeitung eines Unterprogramm-Rücksprungbefehls statt. Das Fehlen eines Unterprogramm-Rücksprungbefehls würde in diesen Ausgestaltungen erst dann entdeckt werden, wenn die Programmausführung über den eigentlich vorgesehenen Rücksprungpunkt hinaus zu einem weiteren Unterprogramm-Rücksprungbefehl gelangt. Um diesen Fall eines fehlenden Rücksprungbefehls sogleich zu erkennen, ist in Ausführungsalternativen vorgesehen, bereits bei der Verarbeitung des Unterprogramm-Aufrufbefehls zu überprüfen, ob an der angegebenen Rücksprungbefehlsadresse des Unterprogramms – oder in den oben genannten Ausführungsalternativen an einer Adresse, die einen vorbestimmten Versatz gegenüber der angegebenen Rücksprungbefehlsadresse aufweist – tatsächlich ein Unterprogramm-Rücksprungbefehl vorhanden ist.In some embodiments of the invention takes place the aforementioned plausibility check only when processing a subroutine return instruction. The Absence of a subroutine return instruction would in these designs can only be discovered when the program execution via the intended return point another subroutine return instruction is reached. Around this case of a missing return command Recognizing immediately is provided in alternative designs, to check whether the subroutine call instruction is already being processed at the specified return command address of the subroutine - or in the above alternative designs at an address that has a predetermined offset from the specified return command address has - actually a subroutine return instruction is available.

Der erfindungsgemäße Prozessor und der Datenträger weisen in bevorzugten Weiterbildungen Merkmale auf, die den oben erwähnten und/ oder den in den abhängigen Verfahrensansprüchen genannten Merkmalen entsprechen.The processor according to the invention and the data carrier have in preferred further developments features which correspond to those mentioned above and / or that in the dependent method claims correspond to the mentioned characteristics.

Weitere Merkmale, Aufgaben und Vorteile der Erfindung ergeben sich aus der folgenden Beschreibung eines Ausführungsbeispiels und mehrerer Ausführungsalternativen. Es wird auf die schematischen Zeichnungen verwiesen, in denen zeigen:Other characteristics, tasks and advantages of Invention result from the following description of an embodiment and several alternative versions. Reference is made to the schematic drawings, in which:

1 ein Blockdiagramm eines tragbaren Datenträgers, der einen Prozessor nach einem Ausführungsbeispiel der Erfindung aufweist, und 1 a block diagram of a portable data carrier having a processor according to an embodiment of the invention, and

2 eine beispielhafte Darstellung des Programmflusses und des Inhalts des Stapelspeichers bei einem Unterprogramm-Aufrufverfahren nach einem Ausführungsbeispiel der Erfindung. 2 an exemplary representation of the program flow and the content of the stack in a subroutine call method according to an embodiment of the invention.

In 1 ist ein tragbarer Datenträger 10 gezeigt, der beispielsweise als Chipkarte oder Chipmodul ausgebildet ist. In an sich bekannter Weise enthält der Datenträger 10 einen Halbleiterchip, auf dem ein Prozessor 12, ein Speicher 14 und eine Schnittstelle 16 zur drahtgebundenen oder drahtlosen Kommunikation ausgebildet sind. Der Speicher 14 weist mehrere unterschiedliche Bereiche auf, nämlich im vorliegenden Ausführungsbeispiel einen als RAM ausgestalteten Arbeitsspeicher 18, einen als EEPROM ausgestalteten nichtflüchtigen Speicher 20 und einen als maskenprogrammiertes ROM ausgestalteten Festwertspeicher 22.In 1 is a portable data carrier 10 shown, which is designed for example as a chip card or chip module. The data carrier contains in a manner known per se 10 a semiconductor chip on which a processor 12 , a memory 14 and an interface 16 are designed for wired or wireless communication. The memory 14 has several different areas, namely in the present exemplary embodiment a working memory configured as RAM 18 , a non-volatile memory configured as an EEPROM 20 and a read-only memory configured as a mask-programmed ROM 22 ,

Der Festwertspeicher 22 enthält wesentliche Teile des Betriebssystems des Datenträgers 10 und der von diesem Betriebssystem ausgeführten Programme. Zwei Programmabschnitte sind in 1 beispielhaft gezeigt, nämlich ein aufrufendes Programm oder Hauptprogramm 24 und ein aufgerufenes Programm oder Unterprogramm 26. Der Prozessor 12 weist einen in Form eines Prozessorregisters ausgestalteten Programmzähler 28 auf, welcher die Adresse des jeweils ausgeführten oder auszuführenden Programmbefehls angibt. Weitere Abschnitte der auszuführenden Programme können im nicht-flüchtigen Speicher 20 enthalten sein. Primär befindet sich in diesem Speicher 20 jedoch ein Dateisystem, auf das die Programme zugreifen, sowie weitere von dem Betriebssystem verwaltete Daten.The read-only memory 22 contains essential parts of the operating system of the data carrier 10 and the programs executed by this operating system. Two program sections are in 1 shown by way of example, namely a calling program or main program 24 and a called program or subroutine 26 , The processor 12 has a program counter designed in the form of a processor register 28 which indicates the address of the program command being executed or to be executed. Further sections of the programs to be executed can be stored in the non-volatile memory 20 be included. This memory is primarily located 20 however, a file system that the programs access and other data managed by the operating system.

Die Begriffe "Hauptprogramm" und "Unterprogramm" bezeichnen vorliegend lediglich die Beziehung der Programmabschnitte 24 und 26 relativ zueinander. Es versteht sich, daß das Hauptprogramm 24 seinerseits von einem übergeordneten Programmabschnitt aufgerufen werden kann, und daß das Unterprogramm 26 seinerseits weitere Unterprogramme aufrufen kann und somit für diese weiteren Unterprogramme als Hauptprogramm anzusehen ist.In the present case, the terms “main program” and “subroutine” only refer to the relationship of the program sections 24 and 26 relative to each other. It is understood that the main program 24 in turn can be called by a higher-level program section, and that the subroutine 26 can in turn call up further subroutines and is therefore to be regarded as the main program for these further subroutines.

Der Arbeitsspeicher 18 dient zur temporären Aufnahme von Werten während Berechnungsvorgängen. Insbesondere ist im Arbeitsspeicher 18 ein Stapelspeicher 30 (stack) angelegt, der unter anderem Unterprogramm-Rücksprungadressen enthält. Der aktuelle Füllungsgrad des Stapelspeichers 30 – also in unterschiedlichen Ausführungsformen entweder der jüngste Eintrag oder der erste noch freie Speicherplatz – wird durch einen Stapelzeiger 32 angegeben, der als Register des Prozessors 12 ausgestaltet ist.The memory 18 is used for the temporary recording of values during calculation processes. In particular, it is in memory 18 a stack 30 (stack) created, which among other things contains subroutine return addresses. The current fill level of the stack 30 - So in different embodiments, either the most recent entry or the first free space - is shown by a stack pointer 32 specified as the register of the processor 12 is designed.

In den in 2 beispielhaft gezeigten Programmabschnitten befindet sich ein Unterprogramm-Aufrufbefehl 34 an der Adresse 0×1111 des Hauptprogramms 24. Der Unterprogramm-Aufrufbefehl 34 weist als Parameter eine Unterprogramm-Startadresse 36 auf, die in 2 mit dem beispielhaften Wert 0×2345 angegeben ist. Ferner enthält der Unterprogramm-Aufrufbefehl 34 als weiteren Parameter eine Rücksprungbefehlsadresse 38, die in 2 den beispielhaften Wert 0×2810 aufweist.In the in 2 There is a subroutine call instruction as an example of the program sections shown 34 at the address 0 × 1111 of the main program 24 , The subroutine call instruction 34 assigns a subroutine start address as a parameter 36 on that in 2 is given with the exemplary value 0x2345. The subroutine call instruction also contains 34 a return command address as a further parameter 38 , in the 2 has the exemplary value 0x2810.

Das Unterprogramm 26 beginnt an der Unterprogramm-Startadresse 36 und endet – bei einer fehlerfreien Programmausführung – mit einem Unterprogramm-Rücksprungbefehl 40, welcher sich an der Rücksprungbefehlsadresse 38 befindet. Die vom Programmierer vorgesehene Ablaufreihenfolge verläuft also vom Unterprogramm-Aufrufbefehl 34 zur Unterprogramm-Startadresse 36 und – nach Ausführung des Unterprogramms 26 – über den Unterprogramm-Rücksprungbefehl 40 zu demjenigen Befehl des Hauptprogramms 24, welcher dem Unterprogramm-Aufrufbefehl 34 unmittelbar folgt. Die Adresse dieses Folgebefehls 42 ist die Zieladresse 44 des Rücksprungs vom Unterprogramm 26; sie ist in 2 beispielhaft mit dem Wert 0×1116 angegeben.The subroutine 26 starts at the subroutine start address 36 and ends - if the program has been executed correctly - with a subroutine return command 40 which is at the return command address 38 located. The execution sequence provided by the programmer therefore runs from the subroutine call instruction 34 to the subroutine start address 36 and - after execution of the subroutine 26 - via the subroutine return command 40 to that command of the main program 24 which the subroutine call instruction 34 immediately follows. The addresses of this follow-up command 42 is the destination address 44 the return from the subroutine 26 ; she is in 2 given as an example with the value 0x1116.

Wenn der Prozessor 12 im Zuge der Programmausführung den Unterprogramm-Aufrufbefehl 34 erkennt, schreibt er zunächst die Rücksprung-Zieladresse 44 in den Stapelspeicher 30. Diese Rücksprung-Zieladresse 44 ist insofern vom aktuellen Stand des Programmzählers 28 abhängig, als sie stets die Adresse des auf den aktuell bearbeiteten Unterprogramm-Aufrufbefehl 34 folgenden Befehls 42 angibt. Im vorliegenden Ausführungsbeispiel ist die Rücksprung-Zieladresse 44 identisch mit dem aktuellen Stand des Programmzählers 28 bei der Ausführung des Unterprogramm-Aufrufbefehls 34, weil der Programmzähler 28 zu diesem Zeitpunkt bereits inkrementiert wurde und somit die Adresse des Folgebefehls 42 enthält. Es sind jedoch auch Ausgestaltungen vorgesehen, bei denen die Rücksprung-Zieladresse 44 einen Versatz gegenüber dem jeweils aktuellen Stand des Programmzählers 28 aufweist.If the processor 12 in the course of the program execution the subroutine call instruction 34 recognizes, it first writes the return destination address 44 into the stack 30 , This return destination address 44 is in this respect of the current status of the program counter 28 dependent, as it always the address of the currently processed subroutine call instruction 34 following command 42 indicates. In the present exemplary embodiment, the return destination address is 44 identical to the current status of the program counter 28 when executing the subroutine call instruction 34 because the program counter 28 has already been incremented at this point and thus the address of the subsequent command 42 contains. However, configurations are also provided in which the return destination address 44 an offset from the current status of the program counter 28 having.

Bei der Ausführung des Unterprogramm-Aufrufbefehls 34 liest der Prozessor 12 ferner die in dem Unterprogramm-Aufrufbefehl 34 enthaltene Rücksprungbefehlsadresse 38 ein und speichert diese ebenfalls im Stapelspeicher 30. In an sich bekannter Weise wird bei jedem Schreibvorgang in den Stapelspeicher 30 der Inhalt des Stapelzeigers 32 angepaßt, also beispielsweise dekrementiert. 2 zeigt den Inhalt des Stapelspeichers 30 nach den gerade beschriebenen Speichervorgängen. Der Übersichtlichkeit halber sind in 2 alle Adressen – unabhängig von der Wortbreite und Organisation des Prozessors 12 und des Speichers 14 – als 16-Bit-Datenworte dargestellt.When executing the subroutine call instruction 34 the processor reads 12 also those in the subroutine call instruction 34 Return instruction address included 38 and also saves them in the stack 30 , In a manner known per se, the stack is stored in each write operation 30 the content of the stack pointer 32 adjusted, e.g. decremented. 2 shows the contents of the stack 30 after the saving processes just described. For the sake of clarity, in 2 all addresses - regardless of the word length and organization of the processor 12 and memory 14 - represented as 16-bit data words.

Nach den genannten Speichervorgängen schließt der Prozessor 12 die Ausführung des Unterprogramm-Aufrufbefehls 34 ab, indem er die in diesem Befehl enthaltene Unterprogramm-Startadresse 36 in den Programmzähler 28 lädt. Die Programmausführung wird dadurch an der Unterprogramm-Startadresse 36, also beim ersten Befehl des Unterprogramms 26, fortgesetzt. In Ausführungsvarianten erfolgt vor diesem Sprung noch eine Überprüfung, ob sich an der im Unterprogramm-Aufrufbefehl 36 angegebenen Rücksprungbefehlsadresse 38 tatsächlich ein für den Unterprogramm-Rücksprungbefehl 40 passender Operationscode (opcode) befindet. Ist dies nicht der Fall, so wird auf die unten noch genauer beschriebene Weise eine Fehlerbehandlungsroutine aufgerufen.The processor closes after the aforementioned storage processes 12 the execution of the subroutine call instruction 34 by entering the subroutine start address contained in this command 36 in the program counter 28 invites. The program execution is thereby at the subroutine start address 36 , i.e. the first command of the subroutine 26 , continued. In execution variants, a check is carried out before this jump as to whether the subroutine call instruction 36 specified return command address 38 actually one for the subroutine return instruction 40 suitable opcode is located. If this is not the case, an error handling routine is called in the manner described in more detail below.

Nach dem Unterprogrammaufruf führt der Prozessor 12 die Befehle des Unterprogramms 26 aus, bis er – bei korrekter Programmierung und korrektem Programmablauf – zum Unterprogramm-Rücksprungbefehl 40 gelangt. Im Zuge der Ausführung dieses Unterprogramm-Rücksprungsbefehls 40 überprüft der Prozessor, ob die im Stapelspeicher 30 als aktueller Eintrag enthaltene Rücksprungbefehlsadresse 38 mit der tatsächlichen Adresse des ausgeführten Unterprogramm-Rücksprungbefehls 40 übereinstimmt. Diese tatsächliche Adresse kann aus dem aktuellen Stand des Programmzählers 28 – gegebenenfalls unter Addition oder Subtraktion eines vorgegebenen Versatzes – bestimmt werden. In Ausführungsalternativen kann auch vorge sehen sein, daß die im Unterprogramm-Aufrufbefehl 34 enthaltene und im Stapelspeicher 30 gespeicherte Rücksprungbefehlsadresse 38 bereits einen gegebenenfalls erforderlichen Versatz aufweist. Schließlich sind auch Ausführungsalternativen denkbar, bei denen der Prozessor 12 den Versatz im Zuge des Speicherns der Rücksprungbefehlsadresse 38 im Stapelspeicher 30 addiert oder subtrahiert.After the subroutine call, the processor runs 12 the commands of the subroutine 26 off until - with correct programming and correct program sequence - to the subroutine return command 40 arrives. In the course of executing this subroutine return instruction 40 the processor checks to see if they are in stack 30 Return command address contained as current entry 38 with the actual address of the executed subroutine return instruction 40 matches. This actual address can be from the current status of the program counter 28 - if necessary by adding or subtracting a given offset. In execution alternatives can also be seen that the in the subroutine call 34 contained and in the stack 30 stored return command address 38 already has a necessary offset. Finally, alternative embodiments are also conceivable in which the processor 12 the offset as the return instruction address 38 is stored in the stack 30 added or subtracted.

Wenn bei der gerade genannten Überprüfung eine Übereinstimmung zwischen der erwarteten Rücksprungbefehlsadresse 38 und der tatsächlichen Adresse des aktuellen Unterprogramm-Rücksprungbefehls 40 festgestellt wird, so wird der Unterprogramm-Rücksprung ausgeführt. Hierbei entfernt der Prozessor 12 zunächst die Rücksprungbefehlsadresse 38 aus dem Stapelspeicher 30, indem er, ohne den Inhalt des Stapelspeichers 30 zu überschreiben, den Stapelzeiger 32 auf den bisher zweitjüngsten Eintrag im Stapelspeicher 30 – nämlich die Rücksprung-Zieladresse 44 – setzt. Der Prozessor 12 lädt dann die Rücksprung-Zieladresse 44 aus dem Stapelspeicher 30 in den Programmzähler 28. Auch in diesem Zusammenhang ist in Ausführungsalternativen vorgesehen, einen vorgegebenen Versatz zu der Rücksprung-Zieladresse 44 zu addieren oder von dieser zu subtrahieren. Nun wird die Rücksprung-Zieladresse 44 vom Stapelspeicher 30 entfernt, indem der Stapelzeiger 32 entsprechend verändert – im vorliegenden Ausführungsbeispiel inkrementiert – wird. Die Programmausführung wird dann mit dem Folgebefehl 42 des Hauptprogramms 24 fortgesetzt.If, in the check just mentioned, there is a match between the expected return command address 38 and the actual address of the current subroutine return instruction 40 the subroutine return is executed. Here, the processor removes 12 first the return command address 38 from the stack 30 by doing without the contents of the stack 30 to overwrite the stack pointer 32 to the second most recent entry in the stack 30 - namely the return destination address 44 - puts. The processor 12 then loads the return destination address 44 from the stack 30 in the program counter 28 , In this context too, alternative embodiments provide for a predetermined offset to the return destination address 44 to add or subtract from this. Now the return destination address 44 from the stack 30 removed by the stack pointer 32 changed accordingly - incremented in the present embodiment - is. The program execution is then followed by the command 42 of the main program 24 continued.

Falls bei der Ausführung des Unterprogramms 26 ein Hardwarefehler auftrat, oder falls ein logischer Programmierfehler vorliegt, so wird nicht der an der Rücksprungbefehlsadresse 38 befindliche Unterprogramm-Rücksprungbefehl 40 erreicht, sondern ein anderer Unterprogramm-Rücksprungbefehl (in 2 nicht gezeigt). Die Ausführung dieses anderen Unterprogramm- Rücksprungbefehls beginnt auf die gerade beschriebene Weise. Allerdings stellt der Prozessor 12 dann bei dem Vergleich der im Stapelspeicher 30 gespeicherten Rücksprungbefelsadresse 38 mit der Adresse des aktuellen Unterprogramm-Rücksprungbefehls eine Abweichung fest. Dies hat zur Folge, daß der Prozessor 12 im vorliegenden Ausführungsbeispiel eine hardwaremäßige, nicht-maskierbare Unterbrechung (non-maskable interrupt – NMI) auslöst.If when executing the subroutine 26 a hardware error has occurred, or if there is a logic programming error, it will not be at the return command address 38 current subroutine return command 40 reached, but another subroutine return instruction (in 2 Not shown). The execution of this other subroutine return instruction begins in the manner just described. However, the processor provides 12 then comparing those in the stack 30 saved return address 38 a deviation with the address of the current subroutine return instruction. As a result, the processor 12 triggers a hardware, non-maskable interrupt (non-maskable interrupt - NMI) in the present exemplary embodiment.

Auf an sich bekannte Weise bewirkt diese Unterbrechung, daß eine Unterbrechungs-Behandlungsroutine (interrupt handler) an einer durch einen Unterbrechungsvektor vorgegebenen Adresse angesprungen wird, welche ihrerseits zu einer geeigneten Fehlerbehandlungsroutine verzweigt. In Ausführungsalternativen kann die Fehlerbehandlungsroutine auch auf andere Weise – z.B. über einen eigens für diesen Zweck vorgesehenen Fehlerbehandlungsvektor – aufgerufen werden.In a manner known per se, this interruption causes an interrupt handler to be sent to an address specified by an interrupt vector is jumped, which in turn branches to a suitable error handling routine. In alternative embodiments, the error handling routine can also be called up in another way - for example via an error handling vector provided specifically for this purpose.

Bei der Programmierung des hier beschriebenen Prozessors 12 werden geeignete Werkzeuge eingesetzt, welche Unterprogramm-Aufrufbefehle 34 mit den erforderlichen Parametern – hier also insbesondere der Rücksprungbefehlsadresse 38 – zu erzeugen vermögen. So kann z.B. vorgesehen sein, daß der Programmierer auf Assembler-Ebene die von ihm intendierte Rücksprungbefehlsadresse 38 als Parameter des Unterprogramm-Aufrufbefehls 34 ausdrücklich angibt. Komplexere Werkzeuge, wie z.B. Compiler, können im Zuge der Codeerzeugung die Rücksprungbefehlsadresse 38 eines automatisch generierten Unterprogramms 26 ermitteln und diese Adresse 38 selbstständig in den Unterprogramm-Aufrufbefehl 34 einfügen. In diesem Fall werden die erfindungsgemäßen Vorteile erreicht, ohne daß bei der Programmierung irgendein zusätzlicher Aufwand erforderlich wäre.When programming the processor described here 12 Suitable tools are used, which subroutine call commands 34 with the required parameters - here in particular the return command address 38 - able to produce. For example, it can be provided that the programmer at the assembler level has the intended return instruction address 38 as a parameter of the subroutine call instruction 34 expressly states. More complex tools, such as compilers, can use the return command address in the course of code generation 38 an automatically generated subroutine 26 determine and this address 38 independently in the subroutine call command 34 insert. In this case, the advantages according to the invention are achieved without any additional effort being required during programming.

Claims (10)

Verfahren zur überwachten Unterprogrammausführung durch einen Prozessor (12), der einen Programmzähler (28) aufweist und der auf einen Stapelspeicher (30) zugreift, mit den ansprechend auf einen Unterprogramm-Aufrufbefehl (34) ausgeführten Schritten: – Speichern einer vom aktuellen Stand des Programmzählers (28) abhängigen Rücksprung-Zieladresse (44) und einer durch den Unterprogramm-Aufrufbefehl (34) angegebenen Rücksprungbefehlsadresse (38) in dem Stapelspeicher (30), und – Fortsetzen der Programmausführung an einer in Abhängigkeit von dem Unterprogramm-Aufrufbefehl (34) ermittelten Startadresse (36) eines Unterprogramms (26), und ferner mit den ansprechend auf einen Unterprogramm-Rücksprungbefehl (40) ausgeführten Schritten: – Überprüfen, ob die Adresse des Unterprogramm-Rücksprungbefehls (40) und die im Stapelspeicher (30) vorhandene Rücksprungbefehlsadresse (38) in einer vorgegebenen Beziehung zueinander stehen, – wenn die vorgegebene Beziehung besteht, Ausführen eines Unterprogramm-Rücksprungs, und – wenn die vorgegebene Beziehung nicht besteht, Aufrufen einer Fehlerbehandlungsroutine.Process for the monitored subroutine execution by a processor ( 12 ) which has a program counter ( 28 ) and on a stack memory ( 30 ) accesses in response to a subroutine call instruction ( 34 ) steps: - Saving one of the current status of the program counter ( 28 ) dependent return destination address ( 44 ) and one by the subroutine call instruction ( 34 ) specified return command address ( 38 ) in the stack ( 30 ), and - resuming program execution on a function of the subroutine call instruction ( 34 ) determined start address ( 36 ) a subroutine ( 26 ), and further in response to a subroutine return instruction ( 40 ): - Check that the address of the subroutine return instruction ( 40 ) and those in the stack ( 30 ) existing return command address ( 38 ) are in a predefined relationship to one another, - if the predefined relationship exists, executing a subroutine return, and - if the predefined relationship does not exist, calling an error handling routine. Verfahren nach Anspruch 1, dadurch gekennzeichnet, daß die vorgegebene Beziehung genau dann besteht, wenn die Adresse des gerade ausgeführten Unterprogramm-Rücksprungbefehls (40) mit der im Stapelspeicher (30) vorhandenen Rücksprungbefehlsadresse (38) übereinstimmt.Method according to Claim 1, characterized in that the predefined relationship exists precisely when the address of the subroutine return command just executed ( 40 ) with the one in the stack ( 30 ) existing return command address ( 38 ) matches. Verfahren nach Anspruch 1, dadurch gekennzeichnet, daß die vorgegebene Beziehung genau dann besteht, wenn die Adresse des gerade ausgeführten Unterprogramm-Rücksprungbefehls (40) einen vorgegebenen Versatz zu der im Stapelspeicher (30) vorhandenen Rücksprungbefehlsadresse (38) aufweist.Method according to Claim 1, characterized in that the predefined relationship exists precisely when the address of the subroutine return command just executed ( 40 ) a given offset to that in the stack ( 30 ) existing return command address ( 38 ) having. Verfahren nach einem der Ansprüche 1 bis 3, dadurch Gekennzeichnet, daß im Zuge der Ausführung des Unterprogramm-Rücksprungs die Rücksprung-Zieladresse (44) und die Rücksprungbefehlsadresse (38) vom Stapelspeicher (30) entfernt werden, und daß der Programmzähler (28) des Prozessors (12) mit einem von der Rücksprung-Zieladresse (44) abhängigen Wert geladen wird.Method according to one of claims 1 to 3, characterized in that in the course of executing the subroutine return, the return destination address ( 44 ) and the return command address ( 38 ) from the stack ( 30 ) and that the program counter ( 28 ) of the processor ( 12 ) with one of the return destination address ( 44 ) dependent value is loaded. Verfahren nach Anspruch 4, dadurch gekennzeichnet, daß der Prozessor einen Stapelzeiger (32) aufweist, und daß das Entfernen der Rücksprung-Zieladresse (44) und der Rücksprungbefehlsadresse (38) vom Stapelspeicher (30) durch eine entsprechende Veränderung des Standes des Stapelzeigers (32) erfolgt.Method according to Claim 4, characterized in that the processor has a stack pointer ( 32 ) and that removing the return destination address ( 44 ) and the return command address ( 38 ) from the stack ( 30 ) by changing the position of the stack pointer accordingly ( 32 ) he follows. Verfahren nach einem der Ansprüche 1 bis 5, dadurch gekennzeichnet, daß die Fehlerbehandlungsroutine durch einen Unterbrechungsmechanismus aufgerufen wird.Method according to one of claims 1 to 5, characterized in that that the Error handling routine called by an interrupt mechanism becomes. Verfahren nach einem der Ansprüche 1 bis 6, dadurch gekennzeichnet, daß bei der Verarbeitung des Unterprogramm-Aufrufbefehls (34) ferner überprüft wird, ob an der Rücksprungbefehlsadresse (38) oder an einer Adresse, die einen vorgegebenen Ver satz gegenüber der Rücksprungbefehlsadresse (38) aufweist, ein Unterprogramm-Rücksprungbefehl (40) gespeichert ist.Method according to one of Claims 1 to 6, characterized in that when processing the subroutine call instruction ( 34 ) it is also checked whether at the return command address ( 38 ) or at an address that has a specified offset compared to the return command address ( 38 ) has a subroutine return instruction ( 40 ) is saved. Verfahren nach einem der Ansprüche 1 bis 7, dadurch gekennzeichnet, daß der Prozessor (12) Bestandteil eines tragbaren Datenträgers (10), insbesondere einer Chipkarte oder eines Chipmoduls, ist.Method according to one of claims 1 to 7, characterized in that the processor ( 12 ) Part of a portable data carrier ( 10 ), in particular a chip card or a chip module. Prozessor (12), der dazu eingerichtet ist, ein Verfahren nach einem der Ansprüche 1 bis 8 auszuführen.Processor ( 12 ), which is set up to carry out a method according to any one of claims 1 to 8. Tragbarer Datenträger (10), insbesondere Chipkarte oder Chipmodul, der einen Prozessor (12) nach Anspruch 9 aufweist.Portable disk ( 10 ), in particular chip card or chip module, which has a processor ( 12 ) according to claim 9.
DE2002152347 2002-11-11 2002-11-11 Subroutine execution monitoring method, stores subroutine return address in program stack then compares with address given by subroutine return command to determine if error has occurred Ceased DE10252347A1 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
DE2002152347 DE10252347A1 (en) 2002-11-11 2002-11-11 Subroutine execution monitoring method, stores subroutine return address in program stack then compares with address given by subroutine return command to determine if error has occurred

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
DE2002152347 DE10252347A1 (en) 2002-11-11 2002-11-11 Subroutine execution monitoring method, stores subroutine return address in program stack then compares with address given by subroutine return command to determine if error has occurred

Publications (1)

Publication Number Publication Date
DE10252347A1 true DE10252347A1 (en) 2004-05-19

Family

ID=32115425

Family Applications (1)

Application Number Title Priority Date Filing Date
DE2002152347 Ceased DE10252347A1 (en) 2002-11-11 2002-11-11 Subroutine execution monitoring method, stores subroutine return address in program stack then compares with address given by subroutine return command to determine if error has occurred

Country Status (1)

Country Link
DE (1) DE10252347A1 (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2006103381A1 (en) * 2005-03-30 2006-10-05 Arm Limited Selecting subroutine return mechanisms
FR2928755A1 (en) * 2008-03-14 2009-09-18 Sagem Securite Sa METHOD FOR SECURING A PROGRAM EXECUTION
DE102009005764A1 (en) 2009-01-23 2010-07-29 Giesecke & Devrient Gmbh Method for monitoring execution of program in e.g. chip card, involves determining whether addressed programs or addresses are assigned to subprogram or destination address, and executing subprogram when assignment is correct
EP2684152A1 (en) * 2011-03-09 2014-01-15 Irdeto B.V. Method and system for dynamic platform security in a device operating system
EP2996034A1 (en) * 2014-09-11 2016-03-16 Nxp B.V. Execution flow protection in microcontrollers

Cited By (16)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2006103381A1 (en) * 2005-03-30 2006-10-05 Arm Limited Selecting subroutine return mechanisms
US7401210B2 (en) 2005-03-30 2008-07-15 Arm Limited Selecting subroutine return mechanisms
JP2008535072A (en) * 2005-03-30 2008-08-28 アーム・リミテッド Selective subroutine return structure
CN101971185B (en) * 2008-03-14 2013-08-07 摩福公司 Method of securing execution of a program
WO2009115712A2 (en) * 2008-03-14 2009-09-24 Sagem Securite Method of securing execution of a program
WO2009115712A3 (en) * 2008-03-14 2009-11-12 Sagem Securite Method of securing execution of a program
RU2468428C2 (en) * 2008-03-14 2012-11-27 Морфо Method for protection of programme execution
FR2928755A1 (en) * 2008-03-14 2009-09-18 Sagem Securite Sa METHOD FOR SECURING A PROGRAM EXECUTION
US8621617B2 (en) 2008-03-14 2013-12-31 Morpho Method of securing execution of a program
DE102009005764A1 (en) 2009-01-23 2010-07-29 Giesecke & Devrient Gmbh Method for monitoring execution of program in e.g. chip card, involves determining whether addressed programs or addresses are assigned to subprogram or destination address, and executing subprogram when assignment is correct
EP2684152A1 (en) * 2011-03-09 2014-01-15 Irdeto B.V. Method and system for dynamic platform security in a device operating system
EP2684152A4 (en) * 2011-03-09 2014-08-20 Irdeto Bv Method and system for dynamic platform security in a device operating system
US9635048B2 (en) 2011-03-09 2017-04-25 Irdeto B.V. Method and system for dynamic platform security in a device operating system
US10333967B2 (en) 2011-03-09 2019-06-25 Irdeto B.V. Method and system for dynamic platform security in a device operating system
EP2996034A1 (en) * 2014-09-11 2016-03-16 Nxp B.V. Execution flow protection in microcontrollers
US10223117B2 (en) 2014-09-11 2019-03-05 Nxp B.V. Execution flow protection in microcontrollers

Similar Documents

Publication Publication Date Title
DE4331703C2 (en) Electronic device
EP0011685B1 (en) Programmable memory protection arrangement for microprocessors and circuitry with such an arrangement
EP2188755A1 (en) Method and apparatus for protection of a program against monitoring flow manipulation and against incorrect program running
DE10159901A1 (en) Microcomputer with built-in programmable, non-volatile memory
WO2006015945A2 (en) Method, operating system, and computing device for processing a computer program
EP1810139B1 (en) Method, operating system and computing element for running a computer program
DE102006054169B4 (en) Method and system for centralizing a process sequence check
WO2006032585A1 (en) Method for executing a computer program on a computer system
DE102005040916A1 (en) Memory arrangement and method of operation therefor
EP1037140B1 (en) Method and apparatus providing security during modification of memory contents in control devices
DE10252347A1 (en) Subroutine execution monitoring method, stores subroutine return address in program stack then compares with address given by subroutine return command to determine if error has occurred
DE102007056218A1 (en) Method for the treatment of transient errors in real-time systems, in particular in control units of motor vehicles
DE102005001679B4 (en) Microprocessor device, and method for branch prediction for conditional branch instructions in a microprocessor device
EP1812853B1 (en) Method, operating system and computing element for running a computer program
DE10064025A1 (en) Microprocessor user software booting method, involves blanking specified areas of memory blocks until valid reset vector localizer is found and then executing reset vector and application in valid boot memory area
EP1892639B1 (en) Secure program code execution
DE102016116221A1 (en) Method and device for monitoring the execution of a program code
DE102013202961A1 (en) Method for monitoring stack memory in operating system of control unit of motor vehicle, involves carrying out predefined action if characteristic parameters of stack memory before and after execution of program codes are not identical
DE10229817B4 (en) Method and device for storing a computer program in a program memory of a control device
DE10110050A1 (en) Method for protecting safety-critical program parts or routines from inadvertent execution, especially for automotive use, in which a safety critical routine will only run if a bit pattern has been set by a calling program section
EP1031081B1 (en) Program-controlled unit and method
DE102010042574A1 (en) Method for operating microcontroller of automobile, involves interrupting specific functions by mechanism such that functions are executed without interference from execution of other functions
DE19921114B4 (en) Method for error analysis in processor-controlled devices
DE102022207612A1 (en) Computer-implemented method for verifying a software component of an automated driving function
DE102009005449B4 (en) Processor that evaluates inherent and sequential identifiers assigned to commands for monitoring the control flow

Legal Events

Date Code Title Description
8110 Request for examination paragraph 44
8131 Rejection