JP2009230479A - Microprocessor - Google Patents
Microprocessor Download PDFInfo
- Publication number
- JP2009230479A JP2009230479A JP2008075229A JP2008075229A JP2009230479A JP 2009230479 A JP2009230479 A JP 2009230479A JP 2008075229 A JP2008075229 A JP 2008075229A JP 2008075229 A JP2008075229 A JP 2008075229A JP 2009230479 A JP2009230479 A JP 2009230479A
- Authority
- JP
- Japan
- Prior art keywords
- address
- memory
- return address
- storage
- instruction
- 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.)
- Withdrawn
Links
Images
Landscapes
- Executing Machine-Instructions (AREA)
Abstract
Description
本発明は、スタックスマッシング攻撃によるバッファオーバーフロー発生を検出する技術に関する。 The present invention relates to a technique for detecting occurrence of a buffer overflow due to a stack smashing attack.
近年、コンピュータシステムを使用者の意図しないように動作させて被害を与える悪質プログラムの存在が問題となっている。悪質プログラムを実行させる方法には、バッファオーバーフローを利用する方法があり、その中でも特に、スタックのオーバーフローを利用するスタックスマッシング(stack smashing)と呼ばれる方法が利用されることが多い。 In recent years, the existence of malicious programs that cause damage by causing a computer system to operate unintentionally has become a problem. As a method for executing a malicious program, there is a method using a buffer overflow, and among them, a method called stack smashing that uses a stack overflow is often used.
スタックスマッシング発生の様子を、図8を用いて簡単に説明する。悪意プログラムによる手続きXが呼び出された時、(a)に示すように通常の手続き呼び出し手順で行われるように、スタックポインタレジスタ(SP)とフレームポインタレジスタ(FP)を更新して、手続きX用のスタック領域が確保される。このスタック領域には、プロセッサのレジスタや処理において使用するデータなどが通常保存されている。そして、この手続きXから新たな手続きYを呼び出せるように、スタックポインタ(SP)+20のアドレスに手続きXの呼び出し元への戻り番地(Return Addr.)が保存される。 A state of occurrence of stack smashing will be briefly described with reference to FIG. When the procedure X by the malicious program is called, the stack pointer register (SP) and the frame pointer register (FP) are updated so as to be performed in the normal procedure call procedure as shown in (a), and the procedure X is used. Stack area is secured. This stack area normally stores processor registers and data used in processing. Then, the return address (Return Addr.) To the caller of the procedure X is stored at the address of the stack pointer (SP) +20 so that a new procedure Y can be called from the procedure X.
しかし、手続きXの処理プログラムの例えば入力データをデータバッファに保存する処理において、スタック領域に確保したデータバッファサイズ以上のデータが入力されると、入力データの数の上限の確認がなされていないシステム関数などが利用された場合、(b)に示すようにデータバッファサイズを超えて書込みが行われる。 However, in the process of saving the input data in the data buffer of the procedure X processing program, for example, if data larger than the data buffer size secured in the stack area is input, the upper limit of the number of input data is not confirmed When a function or the like is used, writing is performed exceeding the data buffer size as shown in (b).
このようにすると、手続きXの処理で最初に保存した手続き呼び出し元への戻り番地(Return Addr.)の情報は、あふれたデータで上書きされて、手続きXの処理の終了段階で悪意プログラムが書き換えた戻り番地(Return Addr.)の命令を実行させるようすることができる。 In this way, the information of the return address (Return Addr.) To the procedure caller that was first saved in the procedure X process is overwritten with overflowing data, and the malicious program is rewritten at the end of the procedure X process. The instruction of the return address (Return Addr.) Can be executed.
この問題に対して、スタックに保存された戻り番地(Return Addr.)とスタック中の配列などのバッファ領域との間にガード変数を格納して、手続き呼び出し元への復帰動作時に、ガード変数の有効性を確認してから戻り番地を読み込むようにすることでスタックスマッシングを防止する技術がある(例えば、特許公報1参照。)。 To solve this problem, a guard variable is stored between the return address (Return Addr.) Stored in the stack and a buffer area such as an array in the stack, and when returning to the procedure caller, There is a technique for preventing stack smashing by reading the return address after confirming the validity (see, for example, Patent Publication 1).
また、コンピュータのプロセッサとキャッシュメモリに改造を加えて、手続きXの呼び出し時に戻り番地(Return Addr.)をキャッシュメモリに書込む時に、同時にその複製(レプリカ)をキャッシュメモリ内に保存し、呼び出し元へのリターン時にメモリから読み出された戻り番地(Return Addr.)とレプリカデータとを比較回路で比較して、一致することを確認するようにしてスタックスマッシングを防止する技術がある(例えば、特許公報2参照。)。
しかしながら、ガード変数を用いソフトウェアによってバッファオーバーフローを検出する方法は、検出手順のプログラムコードを挿入できるようにした拡張コンパイラなどを用いることでソースプログラムの修正量を減少させることができるが、手続きXの呼び出し時および呼び出し元へのリターン時に、戻り番地(Return Addr.)をチェックするための余分なプログラムコードが挿入されることに伴う実行時間のオーバーヘッドが生じるという問題がある。 However, the method of detecting a buffer overflow by software using a guard variable can reduce the amount of correction of the source program by using an extended compiler or the like that can insert the program code of the detection procedure. When calling and returning to the caller, there is a problem that an overhead of execution time due to insertion of extra program code for checking a return address (Return Addr.) Occurs.
また、プロセッサとキャッシュメモリの一部を改良しハードウェアによってバッファオーバーフローを検出する方法は、プログラムの再コンパイルの量を減少させるとともに、プログラム実行時間のオーバーヘッドが少なくなるが、手続きXの呼び出しの繰り返しが多い時にも100%の検出を維持するためには、キャッシュメモリに保存される戻り番地のレプリカデータの追い出しを生じさせないWay数の多いキャッシュメモリが必要となり、回路規模が増加する問題となる。回路規模の増加を抑制するため、Way数が少ないキャッシュメモリを使用する場合は、レプリカデータの記憶領域が不足してレプリカデータが追い出されて100%の検出ができない問題がある。 Further, the method of detecting a buffer overflow by hardware by improving a part of the processor and the cache memory reduces the amount of program recompilation and reduces the overhead of program execution time. However, the procedure X is called repeatedly. In order to maintain 100% detection even when there is a large amount of data, a cache memory with a large number of ways that does not cause the replica data at the return address stored in the cache memory to be expelled is required, which increases the circuit scale. When a cache memory with a small number of ways is used in order to suppress an increase in circuit scale, there is a problem that a replica data storage area is insufficient and replica data is evicted and 100% cannot be detected.
本発明は、上記問題を解決するためになされたもので、実行時間のオーバーヘッドの少ないハードウェアによるバッファオーバーフロー検出を可能としながら、少ない付加回路規模で100%のバッファオーバーフロー検出を実現するプロセッサを提供することを目的とする。 The present invention has been made to solve the above-described problem, and provides a processor that realizes 100% buffer overflow detection with a small additional circuit scale while enabling detection of buffer overflow by hardware with low execution time overhead. The purpose is to do.
上記目的を達成するために、本発明のマイクロプロセッサは、手続き呼び出し分岐命令を有し、呼び出し元への戻り番地をメモリに保存できるマイクロプロセッサであって、前記呼び出し元への戻り番地を前記メモリに保存する保存動作を検出する保存検出手段と、前記保存検出手段で検出された保存動作における戻り番地と、その戻り番地を保存する保存番地とを記憶する前記メモリとは異なる記憶手段と、前記メモリの前記保存番地からの読み出し動作を検出する読み出し検出手段と、前記読み出し検出手段で読み出し動作を検出した時に、前記メモリから読み出した戻り番地と前記記憶手段から読み出した戻り番地とを比較して、その比較内容が一致しない時にバッファオーバーフローが発生していることを検出するバッファオーバーフロー検出手段とを有することを特徴とする。 To achieve the above object, a microprocessor of the present invention is a microprocessor having a procedure call branch instruction and capable of storing a return address to a caller in a memory, wherein the return address to the caller is stored in the memory. A storage detection unit for detecting a storage operation to be stored in the storage unit, a storage unit different from the memory for storing a return address in the storage operation detected by the storage detection unit, and a storage address for storing the return address; Read detection means for detecting a read operation from the storage address of the memory, and when a read operation is detected by the read detection means, the return address read from the memory is compared with the return address read from the storage means. , Buffer overflow to detect that a buffer overflow has occurred when the comparison contents do not match And having a low detection means.
本発明によれば、呼び出し元手続きへの復帰の際に、あらかじめスタック領域に保存された戻り番地と保護されたCAMメモリ中に保存された戻り番地をハードウェアで比較することで、バッファオーバーフローの検出が可能となる。このバッファオーバーフロー検出の一連の処理で、CAMメモリ中のエントリの外部メモリへの退避処理、および外部メモリ中のエントリをCAMメモリへ復帰処理についてプログラムによる処理が必要となるが、CAMメモリのエントリ数を最適化することで、プログラム支援を最小限にすることが可能であり、ガード変数などのソフトウェアプログラムによる検出手法よりも高速にバッファオーバーフローを検出することができる。 According to the present invention, when returning to the caller procedure, the return address stored in the stack area in advance and the return address stored in the protected CAM memory are compared by hardware, so that the buffer overflow Detection is possible. This series of buffer overflow detection processing requires processing by a program for saving entries in the CAM memory to the external memory and restoring the entries in the external memory to the CAM memory. The number of entries in the CAM memory By optimizing, it is possible to minimize program support, and it is possible to detect a buffer overflow faster than a detection method using a software program such as a guard variable.
また、CAMメモリのエントリを容量の大きな外部メモリへ退避、復帰させることができるので、全てのバッファオーバーフロー検出が実現できる。 In addition, since entries in the CAM memory can be saved and restored to a large-capacity external memory, all buffer overflows can be detected.
更にまた、対象となるスタック動作に係るプログラム部分を変更する必要がないので再コンパイルや再設計作業を減らすことができる。 Furthermore, since it is not necessary to change the program part related to the target stack operation, recompilation and redesign work can be reduced.
以下、本発明の実施例を説明する。 Examples of the present invention will be described below.
本発明に係るバッファオーバーフロー検出回路を有するマイクロプロセッサの実施例を、図1乃至図7を参照して説明する。 An embodiment of a microprocessor having a buffer overflow detection circuit according to the present invention will be described with reference to FIGS.
図1は、実施例に係るバッファオーバーフロー検出回路を有するマイクロプロセッサ100とプログラムやデータを記憶する外部メモリ200とを外部バス300で接続されたコンピュータシステム1の主要な構成を示すブロック図である。コンピュータシステム1は、図示しないが標準的なコンピュータシステムに装備されるシステム外部との入出力装置や表示装置や記憶装置などを含むことができる。
FIG. 1 is a block diagram illustrating a main configuration of a
図1に示すマイクロプロセッサ100は、MIPSアーキテクチャのプロセッサ部にバッファオーバーフロー検出回路400を付加した構成となっている。このプロセッサ部は、CPU制御回路110、命令レジスタ120、レジスタファイル130、バスインターフェースユニット140等で構成されている。バスインターフェースユニット140と外部メモリ200とは、データバス302を介して互いに接続されてデータが送受され、アドレスバス301によりアドレスが送受される。なお、ブロック図の接続図が煩雑となるため、命令コード(データ)や一部のデータおよびアドレスの信号線ならびに制御線は図示を省略している。
The
バッファオーバーフロー検出回路400は、命令レジスタ120に記憶され解釈される命令の種別を検出するロード・ストア・JAL命令検出回路410と、バッファオーバーフロー検出回路400の動作を制御し、プロセッサ部への割り込み動作によってバッファオーバーフローの発生を通知したりしてプロセッサ部との連係動作を開始させる制御回路420と、JAL(Jump And Link)命令で分岐動作を行うとともに分岐元への戻り番地を記憶するレジスタ番号を保存するRRレジスタ430と、戻り番地を保存する番地を記憶する保存番地レジスタ440と、戻り番地を記憶する戻り番地レジスタ450と、保存番地をタグとしその保存番地と組となる戻り番地をデータとするエントリを複数記憶するCAM(Content Addressable Memory)メモリ500と、戻り番地レジスタ450からの戻り番地とCAM500より読み出された戻り番地のデータとを比較する比較回路510とから構成される。
The buffer
CPU制御回路110は、外部メモリ200からインターフェースユニット140、データバス131を介して命令レジスタ120に読み込まれた命令を解読実行してマイクロプロセッサ100の内部動作を制御するとともに、次に実行する命令の読み込み動作を制御してプログラムの実行順序を制御する。すなわち、解読された命令が分岐命令でなければ、CPU制御回路110に内蔵され図示しないプログラムカウンタから出力されるアドレスをアドレスバス111に出力して、バスインターフェースユニット140を介してアドレスを外部メモリ200に出力する。そして、外部メモリ200の該当するアドレスから読み出された次の命令を命令レジスタ120に読み込む。
The CPU control circuit 110 decodes and executes an instruction read into the
また例えば、命令レジスタ120にSW命令(Store Word:ストア・ワード[レジスタの1ワード長のデータをメモリに保存する命令])が読み込まれていて、その命令が解読実行される場合、SW命令で指定されたレジスタファイル130のレジスタ(ソースレジスタ)からデータを読み出してデータバス131に出力する。同時に、CPU制御回路110内において解読実行中の命令に含まれるアドレス情報やSW命令で指定されたレジスタファイル130のレジスタから読み出されたデータから生成したアドレスをアドレスバス111に出力する。そして、それぞれのバス131,111に接続されたバスインターフェースユニット140を介して、外部アドレスバス301と外部データバス302に接続された外部メモリ200の指定されたアドレスに当該データを書き込むように制御する。なお、データ演算を行う演算回路や、CPU制御回路110及びプロセッサ部の各要素間を接続する制御/状態信号なども図示を省略している。また、説明の都合上プロセッサをMIPSアーキテクチャのプロセッサとしているが、他のアーキテクチャのプロセッサであっても良い。
Also, for example, when the SW instruction (Store Word: an instruction for storing data of one word length of the register in the memory) is read into the
次に、本発明のバッファオーバーフロー検出回路400が対象とするスタックのバッファオーバーフローの検出動作を説明する。
Next, the operation of detecting the buffer overflow of the stack targeted by the buffer
図2は、実施例に係るバッファオーバーフロー検出回路400の主要な制御処理手順を示すフローチャートである。図3は、C言語で記述された手続きXの呼び出し(Procedure call)処理を含むソースプログラムの例を示すソースプログラムリストである。図4および図5は、図3のソースプログラムをコンパイラ(プログラム)でコンパイルして得られたアセンブリコードリストの一部である。図6は、MIPSアーキテクチャプロセッサのレジスタの使用目的の慣例を示す表で、コンパイラなどが特別に指定されない時にレジスタの使用目的を標準的に割り付ける時に参照するものである。図7は、手続き呼び出しおよび呼び出し元への復帰動作時のスタック領域の使用状況の変化を示す図である。
FIG. 2 is a flowchart illustrating a main control processing procedure of the buffer
実施例のバッファオーバーフロー検出回路400の動作を説明する前に、図3のプログラムの実行において、スタック領域がどのように利用されるのかについて図7を用いて説明する。図3のプログラムは実施例説明のための簡単なCプログラムの例であり、main関数からkeisan関数なる手続きXの呼び出しが行われ、keisan関数の処理が終了すると、リターン命令によって手続きXの呼び出し元のmain関数に処理が戻るプログラムである。
Before describing the operation of the buffer
手続きXの呼び出しの際、まず必要なスタック領域が確保された後、そのスタック領域に呼び出し元へのリターンアドレス(戻り番地)をセーブ(レジスタの内容を外部メモリにストア命令で書込み保存)する。呼び出された手続きの処理が行われた後、スタック領域にセーブされたリターンアドレスをロード(外部メモリから指定されたレジスタに読込む)し、スタック領域を開放し、ロードしたリターンアドレスへジャンプ(分岐)することで手続きXの呼び出し元の関数へ戻ることになる。 When the procedure X is called, a necessary stack area is secured first, and then the return address (return address) to the caller is saved in the stack area (the contents of the register are written and saved in the external memory by a store instruction). After the called procedure is processed, the return address saved in the stack area is loaded (read from the external memory into the specified register), the stack area is released, and the jump to the loaded return address (branch) ) To return to the function that called the procedure X.
以下、シェルプログラム(コンピュータシステムカーネルプログラムとユーザの間のインタープリタプログラム)が動作してアクセス可能なコンピュータシステムで、ユーザがmain関数のプログラムを起動させて、上述の一連の動作を行わせた時の実際のプログラムの流れで説明する。 Hereinafter, when the shell program (the interpreter program between the computer system kernel program and the user) is operated and accessed, the user starts the main function program and performs the above-described series of operations. This will be explained in the actual program flow.
まず、シェルプログラムから図5に示すmain関数が呼び出されるが、この時main関数で必要となるスタック領域が確保され、そのスタック領域に呼び出し元のシェルプログラムへのリターンアドレスが保存される。そのスタック領域の使用状況は、図7(a)のようになる。その後、main関数のJAL命令(図5の5A行目)によりkeisan関数に対する手続きXの呼び出しが実行される。図6に示すように、MIPSアーキテクチャのプロセッサでは、32個のレジスタの使用目的が慣例的に定められていて、このJAL命令実行において、命令で特別に指定しない限りレジスタ番号「31」のレジスタにリターンアドレスが格納されると、図5のkeisan関数へジャンプする。 First, the main function shown in FIG. 5 is called from the shell program. At this time, a stack area necessary for the main function is secured, and a return address to the calling shell program is stored in the stack area. The usage status of the stack area is as shown in FIG. Thereafter, the call of procedure X to the keisan function is executed by the JAL instruction of the main function (line 5A in FIG. 5). As shown in FIG. 6, in the processor of the MIPS architecture, the purpose of use of 32 registers is customarily determined. In the execution of this JAL instruction, the register number “31” is assigned to the register unless otherwise specified by the instruction. When the return address is stored, the process jumps to the keisan function of FIG.
このkeisan関数の最初の部分では、まずkeisan関数用のスタック領域が確保され(図4の4A行目)、さらに呼び出し元のmain関数へのリターンアドレスがそのスタック領域に保存される(図4の4B行目)。そして、スタック領域の使用状況は、図7(b)のようになる。図4に示すkeisan関数の処理において、スタック領域に保存しておいたリターンアドレスがレジスタ番号「31」のレジスタにロードされ(図4の4C行目)、keisan関数の最初に確保(図4の4A行目)したスタック領域を開放(図4の4D行目)した後に、ジャンプ命令(図4の4E行目)を実行することで呼び出し元のmain関数へ戻る。この時の、スタック領域の使用状況は、図7(c)のようになる。 In the first part of this keisan function, first, a stack area for the keisan function is secured (line 4A in FIG. 4), and the return address to the caller main function is stored in the stack area (FIG. 4). 4B line). The usage status of the stack area is as shown in FIG. In the process of the keisan function shown in FIG. 4, the return address stored in the stack area is loaded into the register of register number “31” (line 4C in FIG. 4), and secured at the beginning of the keisan function (in FIG. 4). After releasing the stack area (line 4A) (line 4D in FIG. 4), the jump function (line 4E in FIG. 4) is executed to return to the caller main function. The usage status of the stack area at this time is as shown in FIG.
図5のmain関数の処理においても同様に、スタック領域に保存しておいて呼び出し元のシェルスクリプトへのリターンアドレスをレジスタ番号「31」のレジスタにロードした後に、スタック領域を開放してジャンプ命令を実行することで呼び出し元のシェルプログラムへ戻る。 Similarly, in the processing of the main function in FIG. 5, after saving the stack area and loading the return address to the caller shell script into the register of register number “31”, the stack area is released and a jump instruction is issued. To return to the calling shell program.
上記のような手続きXの呼び出し時、および呼び出し元への復帰時の処理を踏まえた上で、実施例のプロセッサ100のバッファオーバーフロー検出回路400の動作を説明する。
The operation of the buffer
図2のフローチャートに示すように、まず、外部メモリ200から命令レジスタ120に読み込まれた命令が、JAL命令であるかロード・ストア・JAL命令検出回路410を用いてモニターする(ステップS100)。JAL命令以外の命令の場合は、外部メモリ200から命令レジスタ120に読み込まれた次の命令に対して、ステップS100を繰り返し実行する。
As shown in the flowchart of FIG. 2, first, it is monitored using the load / store / JAL
ロード・ストア・JAL命令検出回路410によってJAL命令であることを検出した時は、信号線411を介して制御回路420に通知されたJAL命令のrd番号(rdは、リターンアドレス(戻り番地)が格納されるレジスタの識別情報であるレジスタ番号。図4、図5のJAL命令はオペランドによる指定がないのでレジスタの使用目的の慣例どおりにレジスタ番号「31」となる)を信号線421を介してRRレジスタ430に保存する(ステップS110)。
When the load / store / JAL
次に、命令レジスタ120に読み込まれた次の命令が、JAL命令かまたはストア命令であるかをロード・ストア・JAL命令検出回路410によってモニターする(ステップS120)。JAL(分岐動作と分岐元への戻り番地をレジスタに保存する)命令かまたはストア(レジスタの内容をメモリに保存する)命令以外の命令の場合は、命令レジスタ120に読込まれた次の命令に対して、ステップS120を繰り返し実行する。そして、JAL命令が検出された場合は、ステップS110に戻る。
Next, the load / store / JAL
一方、ストア命令が検出された場合は、RRレジスタ430に保存されたレジスタ番号が信号線431を介してロード・ストア・JAL命令検出回路410に入力されているので、ストア命令のソースレジスタ番号とRRレジスタ430に保存されたレジスタ番号が一致するかを調べる(ステップS130)。不一致の場合は、ステップS120に戻り、次に読み込まれる命令のモニターを行う。
On the other hand, when a store instruction is detected, the register number stored in the
レジスタ番号が一致した場合、CPU制御回路110がアドレスバス111に出力したストア命令の指定するストアアドレスを制御回路420に入力する。制御回路420は、信号線422を介して保存番地レジスタ440に受信したストアアドレスを記憶させる。また、ストア命令で指定されてデータバス131に出力されたソースレジスタのデータ(リターンアドレス)を制御回路420に入力される。制御回路420は信号線423を介して戻り番地レジスタ450に受信したリターンアドレスを記憶させる(ステップS140)。
If the register numbers match, the store address specified by the store instruction output from the CPU control circuit 110 to the address bus 111 is input to the
次に、保存番地レジスタ440に記憶された保存番地をタグとし、戻り番地レジスタ450に記憶された戻り番地をデータとするエントリをそれぞれ信号線441および信号線451を介してCAMメモリ500に書み込み記憶させる(ステップS150)。このCAMメモリ500にエントリ書込みステップS150において、CAMメモリ500に書込み余地がない時、CAMメモリ500は信号線502によって制御回路420にエントリFULL状態(F)であることを通知する。
Next, an entry having the storage address stored in the storage address register 440 as a tag and the return address stored in the
これを受けて制御回路420は、CAMメモリ500への書込み動作を停止して、信号線424を介してCPU制御回路110にエントリFULLの割込みを通知する。CPU制御回路110は、割込み通知を受け付けると、エントリFULLの割込み処理プログラムを起動して、CAMエントリRead命令を実行することで、CAMメモリ500の最も古いCAMエントリを図示しないタグおよびデータレジスタに読み込んだ後、それを外部メモリ200に退避させる。
In response to this, the
このタグおよびデータレジスタにアクセスしてプロセッサ部のレジスタファイル130のレジスタとの間で読み書きする専用命令としては、MIPSアーキテクチャの場合、CoProcessorMove命令(mfc2)などが用いられる。割込み処理後、プロセッサ部は中断したプログラム処理を再開させ、制御回路420はCAMメモリ500へのエントリ書込みを行う。ちなみに、市販のマイクロプロセッサには、内蔵するMMU(Memory Management Unit:メモリ管理ユニット)にCAMメモリ技術を使用するものがあり、専用命令などを用いて内蔵するCAMメモリへアクセスすることができる。
In the case of the MIPS architecture, a CoProcessor Move instruction (mfc2) or the like is used as a dedicated instruction for accessing the tag and data register and reading / writing from / to the register of the
次に、命令レジスタ120に読み込まれた次の命令が、JAL命令かまたはロード命令であるかをロード・ストア・JAL命令検出回路410によってモニターする(ステップS160)。JAL命令かまたはロード命令以外の命令の場合は、命令レジスタ120に読込まれた次の命令に対してステップS160を繰り返し実行する。
Next, the load / store / JAL
JAL命令が検出された場合は、ステップS110に戻る。 If a JAL instruction is detected, the process returns to step S110.
ロード・ストア・JAL命令検出回路410によってロード命令が検出された場合は、CPU制御回路110が信号線111に出力したロード命令が指定するアクセスアドレスを制御回路420に入力する。そして、制御回路420は信号線422を介して保存番地レジスタ440にアドレスを記憶する。また、ロード命令で指定されたアクセスアドレスがCPU制御回路110から出力されてアドレスバス111を介してバスインターフェースユニット140に入力される。さらに、バスインターフェースユニット140からメモリアドレスバス301を介して外部メモリ200に読み出しアクセスが行われる。そして外部メモリ200から読み出された戻り番地がメモリデータバス302を介してバスインターフェースユニット140に入力され、バスインターフェースユニット140よりデータバス131を介して制御回路420に入力される。そして、制御回路420は信号線423を介して戻り番地レジスタ450に戻り番地を記憶させる。そうして、保存番地レジスタ440に記憶されたアクセスアドレスをタグとして、CAMメモリ500へアクセスする(ステップS170)。
When the load instruction is detected by the load / store / JAL
保存番地レジスタ440に記憶されたアクセスアドレスをタグとしたエントリがCAMメモリ500に存在しない(ヒットしない)場合は、ステップS160に戻る。
If the entry with the access address stored in the storage address register 440 as a tag does not exist (does not hit) in the
保存番地レジスタ440に記憶されたアクセスアドレスをタグとしたエントリがCAMメモリ500に存在した(ヒットした)場合は、CAMメモリ500からヒットしたことが信号線502を介して制御回路420に通知される。制御回路420は、戻り番地レジスタ450の戻り番地とCAMメモリ500から読み出された戻り番地とをそれぞれ信号線452および信号線501を介して比較回路510に入力して、比較回路510で比較する(ステップS180)。
If an entry with the access address stored in the storage address register 440 as a tag is present (hit) in the
比較回路510の比較結果が一致した時は、スタック領域に保存された手続きXの呼び出し元への戻り番地の書き換えがなく、手続きXの呼び出し処理が正常に終了したことと判断できる。そして、比較回路510から出力される比較結果511を入力する制御回路420は、保存番地レジスタ440に記憶されたアクセスアドレスをタグとするエントリを無効化する処理を行って、CAMメモリ500より一致したエントリを削除する(ステップS190)。このCAMメモリ500にエントリ削除ステップS190において、CAMメモリ500のエントリが無くなる時、CAMメモリ500は信号線502によって制御回路420にエントリEMPTY状態(E)であることを通知する。
When the comparison results of the comparison circuit 510 match, it can be determined that the return address to the caller of the procedure X stored in the stack area is not rewritten, and the call processing of the procedure X is normally completed. Then, the
制御回路420は、信号線424を介してCPU制御回路110にエントリEMPTYの割込みを通知する。CPU制御回路110は、割込み通知を受け付けると、エントリEMPTYの割込みプログラムを起動して、外部メモリ200に退避しているエントリの有無を調べる。そして、エントリが無い場合は割込みを終了し、エントリがある時は、外部メモリ200からエントリを読み出して、CAMメモリ500にエントリを書込んで、割込みプログラムを終了して、プロセッサ部が中断していた処理を再開させる。
The
次に、CAMメモリ500に記憶された有効なエントリ数が「0」であるか調べる(ステップS200)。エントリ数が「0」でない時は、ステップS160に戻り、エントリ数が「0」の時は、ステップS100に戻る。
Next, it is checked whether the number of valid entries stored in the
ステップS180において、比較回路510での比較結果が一致しない場合は、スタック領域に保存されていた戻り番地が書き換えられていることを示し、比較回路510から出力される比較結果511を受ける制御回路420は、信号線424を介してCPU制御回路110にバッファオーバーフロー検出割込みを行う(ステップS210)。
In step S180, if the comparison result in the comparison circuit 510 does not match, the
上述のようにバッファオーバーフロー検出回路400は動作し、呼び出された手続きプログラムで呼び出し元へのリターンアドレスをスタック領域に保存する際に、CAMメモリ500にもリターンアドレスを書込み保存する。
As described above, the buffer
このCAMメモリ500中のリターンアドレスへのアクセスは、バッファオーバーフロー検出回路400に組み込まれた制御手順に従って上述のように手続き呼び出し時および呼び出し元へのリターン時に行われるリターンアドレスへのアクセスと並列に行うように限定されるため、悪意プログラムなどによってスタックバッファオーバーフローのような操作を行うプログラムでは、リターンアドレスを改変することはできない。このようにCAMメモリ500中のリターンアドレスは保護されるので、呼び出し元手続きへの復帰の際に、あらかじめスタック領域に保存されたリターンアドレスとCAMメモリ500中に保存されたリターンアドレスを比較することで、バッファオーバーフローの検出が可能となる。
The access to the return address in the
これら一連の処理で、CAMメモリ500中のエントリの外部メモリ200への退避処理、および外部メモリ200中のエントリをCAMメモリ500へリストア(復帰処理)についてのみプロセッサが実行するソフトウェア(プログラム)の処理の介在が必要となるが、CAMメモリ500のエントリ数を最適化することで、ソフトウェア支援を最小限にすることが可能であり、ガード変数などのソフトウェアプログラムによる検出手法よりも高速にバッファオーバーフローを検出することができる。
In this series of processing, software (program) processing executed by the processor only for saving the entries in the
また、CAMメモリ500のエントリを容量の大きな外部メモリへ退避、復帰させることができるので、100%のバッファオーバーフロー検出が実現できる。更にまた、対象となるスタック動作に係るプログラム部分を変更する必要がないので再コンパイルや再設計作業を減らすことができる。
In addition, since entries in the
本発明は、上記実施例に限定されるものではなく、発明の要旨を逸脱しない範囲で、種々、変形して実施できることは勿論である。 The present invention is not limited to the above-described embodiments, and it is needless to say that various modifications can be made without departing from the spirit of the invention.
例えば、保存番地と戻り番地(リターンアドレス)の組(エントリ)を記憶するCAMメモリをLIFO(Last−In First−Out)動作するLIFOメモリとすることができて、ストア命令を検出し、そのソースレジスタのレジスタ番号がRR430に記憶されたレジスタ番号と一致した場合に、ストア命令のアクセスアドレスの保存番地と保存データの戻り番地の組をLIFOメモリに記憶するようにする。そして、ロード命令を検出し、そのアクセスアドレスがLIFOメモリに記憶された保存番地と一致した場合に、ロード命令で読み出されたデータがLIFOメモリに記憶された戻り番地と一致するかを調べ、不一致の場合にバッファオーバーフローが発生したことを検出するようにすることができる。保存番地レジスタ440とLIFOメモリの保存番地記憶部からの出力を比較する回路の追加などが必要となるが、メモリの構成がCAMメモリに比べて簡単なLIFOメモリを使用することができる。
For example, a CAM memory that stores a pair (entry) of a storage address and a return address (return address) can be a LIFO memory that operates as a LIFO (Last-In First-Out), and a store instruction is detected and its source When the register number of the register matches the register number stored in the
1 コンピュータシステム
100 マイクロプロセッサ
110 CPU制御回路
111 アドレスバス
120 命令レジスタ
130 レジスタファイル
131 データバス
140 バスインターフェースユニット
200 外部メモリ
300 外部バス
301 外部アドレスバス
302 外部データバス
400 バッファオーバーフロー検出回路
410 ロード・ストア・JAL命令検出回路
420 制御回路
430 RRレジスタ
440 保存番地レジスタ
450 戻り番地レジスタ
500 CAMメモリ
510 比較回路
1
Claims (5)
前記呼び出し元への戻り番地を前記メモリに保存する保存動作を検出する保存検出手段と、
前記保存検出手段で検出された保存動作における戻り番地と、その戻り番地を保存する保存番地とを記憶する前記メモリとは異なる記憶手段と、
前記メモリの前記保存番地からの読み出し動作を検出する読み出し検出手段と、
前記読み出し検出手段で読み出し動作を検出した時に、前記メモリから読み出した戻り番地と前記記憶手段から読み出した戻り番地とを比較して、その比較内容が一致しない時にバッファオーバーフローが発生していることを検出するバッファオーバーフロー検出手段と
を有することを特徴とするマイクロプロセッサ。 A microprocessor that has a procedure call branch instruction and can store the return address to the caller in memory,
Storage detection means for detecting a storage operation for storing the return address to the caller in the memory;
A storage unit different from the memory for storing a return address in the storage operation detected by the storage detection unit and a storage address for storing the return address;
Read detection means for detecting a read operation from the storage address of the memory;
When a read operation is detected by the read detection means, the return address read from the memory is compared with the return address read from the storage means, and a buffer overflow occurs when the comparison contents do not match. A microprocessor having a buffer overflow detecting means for detecting.
手続き呼び出し分岐命令が実行される時に呼び出し元への戻り番地を保存するレジスタ識別情報を記憶するレジスタ識別情報記憶手段と、
前記手続き呼び出し分岐命令が実行された後に、ストア命令が実行される時に前記レジスタ識別情報記憶手段に記憶された前記レジスタ識別情報で識別されるレジスタに保存されていたデータがメモリに保存される場合に、保存番地と保存データとを同時に記憶する前記メモリとは異なる記憶手段と、
前記ストア命令が実行された後に、ロード命令が実行される時に前記記憶手段の前記保存番地より前記メモリから読み出されるデータと、前記記憶手段に同時に記憶された前記保存データとを比較して、その比較内容が一致しない時にバッファオーバーフローが発生していることを検出するバッファオーバーフロー検出手段と
を有することを特徴とするマイクロプロセッサ。 A microprocessor that has a procedure call branch instruction and can store the return address to the caller in memory,
Register identification information storage means for storing register identification information for storing a return address to the caller when a procedure call branch instruction is executed;
When the data stored in the register identified by the register identification information stored in the register identification information storage means is stored in the memory when the store instruction is executed after the procedure call branch instruction is executed Storage means different from the memory for simultaneously storing the storage address and the storage data;
After the store instruction is executed, when the load instruction is executed, the data read from the memory from the storage address of the storage means is compared with the stored data simultaneously stored in the storage means, And a buffer overflow detecting means for detecting that a buffer overflow has occurred when the comparison contents do not match.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2008075229A JP2009230479A (en) | 2008-03-24 | 2008-03-24 | Microprocessor |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2008075229A JP2009230479A (en) | 2008-03-24 | 2008-03-24 | Microprocessor |
Publications (1)
Publication Number | Publication Date |
---|---|
JP2009230479A true JP2009230479A (en) | 2009-10-08 |
Family
ID=41245784
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
JP2008075229A Withdrawn JP2009230479A (en) | 2008-03-24 | 2008-03-24 | Microprocessor |
Country Status (1)
Country | Link |
---|---|
JP (1) | JP2009230479A (en) |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP2015011436A (en) * | 2013-06-27 | 2015-01-19 | 株式会社デンソー | Processor |
JP2015191658A (en) * | 2014-03-28 | 2015-11-02 | インテル・コーポレーション | Return-target restrictive return instructions from procedure, processors, methods, and systems |
US10261814B2 (en) | 2014-06-23 | 2019-04-16 | Intel Corporation | Local service chaining with virtual machines and virtualized containers in software defined networking |
-
2008
- 2008-03-24 JP JP2008075229A patent/JP2009230479A/en not_active Withdrawn
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP2015011436A (en) * | 2013-06-27 | 2015-01-19 | 株式会社デンソー | Processor |
JP2015191658A (en) * | 2014-03-28 | 2015-11-02 | インテル・コーポレーション | Return-target restrictive return instructions from procedure, processors, methods, and systems |
US9703948B2 (en) | 2014-03-28 | 2017-07-11 | Intel Corporation | Return-target restrictive return from procedure instructions, processors, methods, and systems |
US10261814B2 (en) | 2014-06-23 | 2019-04-16 | Intel Corporation | Local service chaining with virtual machines and virtualized containers in software defined networking |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
KR101835250B1 (en) | Detection of unauthorized memory modification and access using transactional memory | |
US8161273B2 (en) | Method and apparatus for programmatically rewinding a register inside a transaction | |
US8316366B2 (en) | Facilitating transactional execution in a processor that supports simultaneous speculative threading | |
KR101249693B1 (en) | Selecting subroutine return mechanisms | |
US20050240701A1 (en) | Interrupt control apparatus | |
KR102344010B1 (en) | Handling of inter-element address hazards for vector instructions | |
CN108780397B (en) | Program loop control | |
CN111133418B (en) | Allowing non-aborted transactions after exception mask update instructions | |
US8181063B2 (en) | Computer device, continuing operation method for computer device, and program | |
JP5245237B2 (en) | Error handling method | |
JP2009230479A (en) | Microprocessor | |
JP5215655B2 (en) | Data processing apparatus and bus access control method in data processing apparatus | |
CN115576734B (en) | Multi-core heterogeneous log storage method and system | |
US6889315B2 (en) | Processor and method of controlling the same | |
JP2004326331A (en) | Unauthorized memory access detection method and program of the same | |
US7890740B2 (en) | Processor comprising a first and a second mode of operation and method of operating the same | |
JP2001306334A (en) | Emulation device | |
JP2562838B2 (en) | Processor and store buffer control method | |
CN106537342B (en) | Dynamic saving of registers in transactions | |
JPH08137748A (en) | Computer having copy back cache and copy back cashe control method | |
JP3762608B2 (en) | Computer and its control method | |
KR20080044652A (en) | Method for debugging by using stack of cpu | |
JP2870405B2 (en) | Information processing device | |
JP2015115052A (en) | Microprocessor, computer, method of coping with abnormality, and abnormality countermeasure program | |
JP3748191B2 (en) | Computer and its control method |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
A300 | Withdrawal of application because of no request for examination |
Free format text: JAPANESE INTERMEDIATE CODE: A300 Effective date: 20110607 |