JP2020027512A - Converter, conversion program, and program conversion method - Google Patents

Converter, conversion program, and program conversion method Download PDF

Info

Publication number
JP2020027512A
JP2020027512A JP2018152795A JP2018152795A JP2020027512A JP 2020027512 A JP2020027512 A JP 2020027512A JP 2018152795 A JP2018152795 A JP 2018152795A JP 2018152795 A JP2018152795 A JP 2018152795A JP 2020027512 A JP2020027512 A JP 2020027512A
Authority
JP
Japan
Prior art keywords
address
instruction
return
identification label
program
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.)
Granted
Application number
JP2018152795A
Other languages
Japanese (ja)
Other versions
JP6460433B1 (en
Inventor
平 昌展
Masanobu Taira
昌展 平
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.)
Attc Co Ltd
Original Assignee
Attc Co Ltd
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 Attc Co Ltd filed Critical Attc Co Ltd
Priority to JP2018152795A priority Critical patent/JP6460433B1/en
Application granted granted Critical
Publication of JP6460433B1 publication Critical patent/JP6460433B1/en
Publication of JP2020027512A publication Critical patent/JP2020027512A/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Stored Programmes (AREA)

Abstract

To detect the falsification of a return address by an attack taking advantage of software vulnerability and prevent improper program execution.SOLUTION: The present invention inserts, between a function call instruction and the next instruction included in a conversion target program, an identification label for specifying a place to which to be returned after the processing of a function called by the function call instruction is terminated. The conversion target program is converted so as to calculate the absolute address of the identification label at execution time and hold it. Furthermore, the conversion target program is converted so as to jump to the identification label when the address indicated as a return destination by a return instruction at execution time is found, by determination a match, to match the address to which to be returned (absolute address of the identification label at conversion target program execution time is calculated and held), and to terminate the program when said address does not match, thereby detecting the falsification of the return address and prevent wrongful program execution in advance.SELECTED DRAWING: Figure 1

Description

本発明は、ソフトウェアの脆弱性を利用した攻撃によるリターンアドレスの改ざんを検知して不正なプログラムの実行を防止する技術に関するものである。   The present invention relates to a technique for detecting return address tampering due to an attack using software vulnerability to prevent execution of an unauthorized program.

不正なプログラムをコンピュータにおいて実行することによる情報流出が問題となっている。これらの不正なプログラムは、ソフトウェアの脆弱性を利用するものが多い。   Information leakage due to execution of an unauthorized program on a computer has become a problem. These malicious programs often use software vulnerabilities.

代表的な例としてバッファオーバーフロー攻撃がある。コンピュータでのプログラムの動作において関数が呼び出される際には、当該関数の呼び出し元へ戻ることを可能とするために、リターンアドレスがレジスタ又はメモリ上のスタック領域に格納されるが、関数の脆弱性を利用してスタック領域上のリターンアドレスを不正なアドレスに上書きする攻撃がよく知られている。   A typical example is a buffer overflow attack. When a function is called in the operation of a program on a computer, the return address is stored in a register or a stack area in memory to enable the function to return to the caller of the function. An attack that overwrites a return address on the stack area with an invalid address by using a URL is well known.

特許文献1には、バッファオーバーフローの発生を防ぐようにプログラムを変換する変換装置が記載されている。   Patent Literature 1 discloses a conversion device that converts a program so as to prevent occurrence of a buffer overflow.

特許文献2には、バッファオーバーフローによる不正なプログラムの実行を防止する手段を備えるプロセッサが記載されている。   Patent Literature 2 discloses a processor including means for preventing execution of an unauthorized program due to a buffer overflow.

特許第5820754号公報Japanese Patent No. 5820754 特許第5777843号公報Japanese Patent No. 5777843

しかしながら、バッファオーバーフロー攻撃以外にもソフトウェアの脆弱性を利用して、リターンアドレスを不正なアドレスに書き換える攻撃が存在する。例えば、共有ライブラリが位置独立コード化されていると、実行可能ファイルの実行時に動的リンクによってその絶対アドレスが解決されるために、特許文献1及び特許文献2に記載された発明では、いずれも主処理で呼び出されるプログラムを指し示す絶対アドレスが主処理の実行前にすべて判明していることを前提としているためにリターンアドレスを不正なアドレスに書き換えられたとしても対応ができない。   However, in addition to the buffer overflow attack, there is an attack that rewrites a return address to an illegal address by using a software vulnerability. For example, if the shared library is coded in a position-independent manner, the absolute address of the executable file is resolved by dynamic link at the time of execution of the executable file. Since it is assumed that all the absolute addresses indicating the program called in the main processing are known before the execution of the main processing, it is impossible to cope with the case where the return address is rewritten to an incorrect address.

リターンアドレスをレジスタに退避するとの手段も考えられるが、ハードウェア資源には限界があるため、ソフトウェアによる解決手段が求められる。   Means for saving the return address in a register may be considered, but there is a limit in hardware resources, and a software solution is required.

本発明は、このような事情を鑑みてなされたものであり、前述の課題を解決しつつ、ソフトウェアの脆弱性を利用した攻撃によるリターンアドレスの改ざんを検知して不正なプログラムの実行を防止する変換装置、変換プログラム、プログラム変換方法を提供することを目的とする。   SUMMARY OF THE INVENTION The present invention has been made in view of such circumstances, and solves the above-described problem, detects return address falsification due to an attack using a software vulnerability, and prevents execution of an unauthorized program. It is an object to provide a conversion device, a conversion program, and a program conversion method.

本発明である変換装置、変換プログラム及びコンピュータを用いたプログラム変換方法は、次の仕組みを実現するように変換対象プログラムを変換することで、前述の課題を解決する。   A conversion device, a conversion program, and a program conversion method using a computer according to the present invention solve the above-described problem by converting a conversion target program so as to realize the following mechanism.

(仕組み)
本発明は、変換対象プログラムに含まれる関数呼び出し命令と次の命令との間に、関数呼び出し命令が呼び出した関数の処理が終了した後にリターンすべき場所を特定するための識別ラベルを挿入する。実行時に識別ラベルの絶対アドレスを算出して、保持するように変換対象プログラムを変換する。さらに、実行時にリターン命令がリターン先として指し示すアドレスが、リターンすべきアドレス(算出して保持している変換対象プログラム実行時の識別ラベルの絶対アドレス)と一致しているかを判定して一致する場合にはそのままリターン(識別ラベルにジャンプ)し、一致しない場合にはプログラムを終了させるように変換対象プログラムを変換する。
(Mechanism)
According to the present invention, an identification label for specifying a place to return to after the processing of the function called by the function call instruction is completed is inserted between the function call instruction included in the conversion target program and the next instruction. At the time of execution, an absolute address of the identification label is calculated, and the conversion target program is converted so as to be held. Further, when it is determined whether the address indicated by the return instruction as the return destination at the time of execution matches the address to be returned (the absolute address of the identification label at the time of execution of the conversion target program that is calculated and held) and matches. Is returned (jump to the identification label) as it is, and if they do not match, the conversion target program is converted so as to terminate the program.

前述の仕組みを実現して課題を解決するために、本発明は、変換対象プログラムを構成する実行可能なオブジェクトファイルについて、ソースファイルの存在するディレクトリと、ソースファイルを構成するオブジェクトファイルと、シンボル名と、が互いに紐づく関係を示す関係情報をメモリマップに基づいて生成することを特徴とする。   In order to solve the problem by realizing the above-described mechanism, the present invention provides an executable object file which constitutes a conversion target program, a directory where a source file exists, an object file which constitutes a source file, and a symbol name. Are generated based on the memory map, indicating that the relationship information indicates the relationship between the two.

前述の仕組みを実現して課題を解決するために、本発明は、変換対象プログラムの開始アドレス及び変換対象プログラムにリンクされる共有ライブラリの開始アドレスをメモリマップに基づいて算出し、保持する命令を、変換対象プログラムの実行開始直後に、変換対象プログラムから、この命令を呼び出すことができるように変換対象プログラムに挿入することを特徴とする。なお、本願書面においては、「変換対象プログラムの開始アドレス及び変換対象プログラムにリンクされる共有ライブラリの開始アドレスをメモリマップに基づいて算出し、保持する命令」を「ロードアドレス算出命令」と記述する。以下において同様である。   In order to solve the problem by realizing the above-described mechanism, the present invention calculates a start address of a conversion target program and a start address of a shared library linked to the conversion target program based on a memory map, and issues an instruction to hold the instruction. Immediately after the execution of the conversion target program, the instruction is inserted into the conversion target program so that the instruction can be called from the conversion target program. Note that, in the present specification, the “instruction for calculating and holding the start address of the conversion target program and the start address of the shared library linked to the conversion target program based on the memory map” is referred to as a “load address calculation instruction”. . The same applies to the following.

前述の仕組みを実現して課題を解決するために、本発明は、変換対象プログラムに含まれる関数呼び出し命令を検出し、関数呼び出し命令が呼び出した関数の処理が終了した後にリターンすべき場所を特定するための識別ラベルを生成し、検出した関数呼び出し命令と次の命令との間に識別ラベルを挿入することを特徴とする。   In order to solve the problem by realizing the above-described mechanism, the present invention detects a function call instruction included in a conversion target program and specifies a place to return after processing of the function called by the function call instruction is completed And generating an identification label between the detected function call instruction and the next instruction.

前述の仕組みを実現して課題を解決するために、本発明は、変換対象プログラムに含まれるリターン命令を検出し、検出したリターン命令を、変換対象プログラム実行時にリターン命令がリターン先として指し示すアドレスが識別ラベルのアドレスから算出したリターンすべき絶対アドレスと一致しているかを判定して一致しない場合には変換対象プログラムを終了させるリターンアドレスチェック命令へ分岐する命令、に書き換えることを特徴とする。なお、本願書面においては、「変換対象プログラム実行時にリターン命令がリターン先として指し示すアドレスが識別ラベルアドレスから算出したリターンすべきアドレスと一致しているかを判定して一致しない場合には変換対象プログラムを終了させる命令」を「リターンアドレスチェック命令」と記述する。以下において同様である。   In order to solve the problem by realizing the above-described mechanism, the present invention detects a return instruction included in a conversion target program, and detects the detected return instruction when an address indicated by the return instruction as a return destination when the conversion target program is executed. It is characterized in that it is determined whether or not it matches the absolute address to be returned calculated from the address of the identification label, and if it does not match, the instruction is rewritten to an instruction for branching to a return address check instruction for terminating the program to be converted. Note that, in the present document, it is determined that the address indicated by the return instruction at the time of execution of the conversion target program matches with the address to be returned calculated from the identification label address. The instruction to be terminated is described as a "return address check instruction." The same applies to the following.

前述の仕組みを実現して課題を解決するために、本発明は、変換対象プログラムに、リターンアドレスチェック命令を生成し、挿入することを特徴とする。   In order to realize the above-described mechanism and solve the problem, the present invention is characterized in that a return address check instruction is generated and inserted into a conversion target program.

前述の仕組みを実現して課題を解決するために、本発明は、識別ラベルのアドレスを取得し、取得したアドレスを識別ラベルと紐づけて識別ラベルアドレスとして保持することを特徴とする。   In order to realize the above-described mechanism and solve the problem, the present invention is characterized in that an address of an identification label is acquired, and the acquired address is associated with the identification label and held as an identification label address.

前述の仕組みを実現して課題を解決するために、本発明は、変換対象プログラムが正常起動するかを判定し、正常に起動した場合にはプログラムの変換を終了し、正常に起動しない場合には、識別ラベルアドレスの再取得を命令し、リターンアドレスチェック命令の更新を命令し、再度正常起動するかを判定する処理を行なうことを特徴とする。   In order to solve the problem by realizing the above-described mechanism, the present invention determines whether the conversion target program starts normally, terminates the program conversion if it starts normally, and if it does not start normally Is characterized by performing a process of instructing re-acquisition of an identification label address, instructing an update of a return address check instruction, and determining whether to normally start again.

以上のように本発明によれば、前述の課題を解決して、ソフトウェアの脆弱性を利用した攻撃によるリターンアドレスの改ざんを検知して不正なプログラムの実行を防止することができる。   As described above, according to the present invention, it is possible to solve the above-described problem and detect the falsification of the return address due to the attack using the vulnerability of the software, thereby preventing the execution of the unauthorized program.

変換装置の構成例を示すブロック図である。FIG. 3 is a block diagram illustrating a configuration example of a conversion device. 変換装置のハードウェア構成である。It is a hardware configuration of a conversion device. 変換装置の動作を示すフローチャートである。6 is a flowchart illustrating an operation of the conversion device. 関係情報の例を模式的に示した図である。FIG. 5 is a diagram schematically illustrating an example of relation information. メモリマップの例である。It is an example of a memory map. シンボル名調査のフローチャートである。It is a flowchart of a symbol name search. ロードアドレス算出命令挿入処理を示すフローチャートである。9 is a flowchart illustrating load address calculation instruction insertion processing. ロードアドレス算出命令によって実行される処理フローである。It is a processing flow performed by a load address calculation instruction. 変換された後の変換対象プログラムの動作の概要を説明する図である。FIG. 9 is a diagram illustrating an outline of an operation of a conversion target program after conversion. 識別ラベル生成挿入処理とリターン命令書き換え処理を示すフローチャートである。It is a flowchart which shows an identification label generation insertion process and a return instruction rewriting process. 識別ラベル出力処理を示すフローチャートである。It is a flowchart which shows an identification label output process. リターンアドレスチェック命令生成挿入処理を示すフローチャートである。9 is a flowchart illustrating a return address check instruction generation and insertion process. リターンアドレスチェック命令の生成について説明するフローチャートである。It is a flowchart explaining generation | occurrence | production of a return address check instruction. 識別ラベルアドレス取得処理を示すフローチャートである。It is a flowchart which shows an identification label address acquisition process. リターンアドレスチェック命令更新処理を示すフローチャートである。It is a flowchart which shows a return address check command update process. リターンアドレス更新についての詳細を示すフローチャートである。It is a flowchart which shows the detail about a return address update. 第2実施形態での識別ラベル生成挿入処理を示すフローチャートである。It is a flowchart which shows the identification label production | generation insertion processing in 2nd Embodiment. 標準ライブラリ関数識別ラベル出力について示すフローチャートである。It is a flowchart shown about standard library function identification label output. 第2実施形態でのリターンアドレスチェック命令生成挿入処理を示すフローチャートである。9 is a flowchart illustrating a return address check instruction generation and insertion process according to the second embodiment. 標準関数コール部生成出力処理を示すフローチャートである。It is a flowchart which shows a standard function call part generation output process.

本発明の実施の形態について図面を参照して説明する。なお、各図において同一又は相当部分には同一の符号を付し、重複する説明を省略する。   An embodiment of the present invention will be described with reference to the drawings. In each of the drawings, the same or corresponding portions are denoted by the same reference characters, and redundant description will be omitted.

(第1実施形態)
本実施形態に係る変換装置は、ソフトウェアの脆弱性を利用した攻撃によるリターンアドレスの改ざんを検知して停止するようにプログラムを変換する変換装置である。
(1st Embodiment)
The conversion device according to the present embodiment is a conversion device that converts a program so as to stop and detect alteration of a return address due to an attack using software vulnerability.

図1は、本実施形態による変換装置10の構成を示すブロック図である。図1に示すように、変換装置10は、関係情報生成部100、ロードアドレス算出命令挿入部110、コンパイラ120、識別ラベル生成挿入部130、リターン命令書き換え部140、識別ラベルアドレス取得部150、リターンアドレスチェック命令生成挿入部160、リターンアドレスチェック命令更新部170を備えている。   FIG. 1 is a block diagram illustrating a configuration of a conversion device 10 according to the present embodiment. As shown in FIG. 1, the conversion apparatus 10 includes a relation information generation unit 100, a load address calculation instruction insertion unit 110, a compiler 120, an identification label generation and insertion unit 130, a return instruction rewriting unit 140, an identification label address acquisition unit 150, a return An address check instruction generation / insertion unit 160 and a return address check instruction update unit 170 are provided.

関係情報生成部100は、変換対象プログラムを構成する実行可能なオブジェクトファイルについて、ソースファイルの存在するディレクトリと、ソースファイルを構成するオブジェクトファイルと、シンボル名と、が互いに紐づく関係を示す関係情報をメモリマップに基づいて生成する機能を有している。   The relation information generation unit 100 is configured to execute a relation information indicating a relation in which a directory in which a source file exists, an object file forming the source file, and a symbol name are linked to each other with respect to an executable object file forming the conversion target program. Is generated based on the memory map.

ロードアドレス算出命令挿入部110は、ロードアドレス算出命令を、変換対象プログラムの実行開始直後に、変換対象プログラムから、この命令を呼び出すことができるように変換対象プログラムに挿入する機能を有している。   The load address calculation instruction insertion unit 110 has a function of inserting a load address calculation instruction into the conversion target program so that the instruction can be called from the conversion target program immediately after the execution of the conversion target program starts. .

コンパイラ120は、変換対象プログラムのソースプログラムを実行可能ファイル及び共有ライブラリなどのオブジェクトファイルまたはアセンブリプログラムに変換する。   The compiler 120 converts the source program of the conversion target program into an object file such as an executable file and a shared library or an assembly program.

識別ラベル生成挿入部130は、変換対象プログラムに含まれる関数呼び出し命令を検出し、関数呼び出し命令が呼び出した関数の処理が終了した後にリターンすべき場所を特定するための識別ラベルを生成し、検出した関数呼び出し命令と次の命令との間に識別ラベルを挿入する機能を有している。   The identification label generation / insertion unit 130 detects a function call instruction included in the conversion target program, and generates an identification label for specifying a place to return to after the processing of the function called by the function call instruction is completed. A function of inserting an identification label between the function call instruction and the next instruction.

リターン命令書き換え部140は、変換対象プログラムに含まれるリターン命令を検出し、検出したリターン命令を、リターンアドレスチェック命令へ分岐する命令、に書き換える機能を有している。   The return instruction rewriting unit 140 has a function of detecting a return instruction included in the conversion target program and rewriting the detected return instruction into an instruction that branches to a return address check instruction.

リターンアドレスチェック命令生成挿入部160は、変換対象プログラムに、リターンアドレスチェック命令を生成し、挿入する機能を有している。   The return address check instruction generation / insertion unit 160 has a function of generating and inserting a return address check instruction in the conversion target program.

識別ラベルアドレス取得部150は、オブジェクトファイルから識別ラベルのアドレスを取得し、取得したアドレスを識別ラベルと紐づけて識別ラベルアドレスとして保持する機能を有している。   The identification label address acquisition unit 150 has a function of acquiring the address of the identification label from the object file, linking the acquired address with the identification label, and holding the acquired address as the identification label address.

リターンアドレスチェック命令更新部170は、変換対象プログラムが正常起動するかを判定し、正常に起動した場合にはプログラムの変換を終了し、正常に起動しない場合には、識別ラベルアドレスの再取得を命令し、リターンアドレスチェック命令の更新を命令し、再度正常起動するかを判定する処理を行なう機能を有している。   The return address check instruction updating unit 170 determines whether the conversion target program starts normally, terminates the conversion of the program if it starts normally, and reacquires the identification label address if it does not start normally. It has a function to issue a command, update a return address check command, and determine whether or not to normally start again.

図1に示す変換装置10は、図2に示すハードウェア構成20を有する。図2に示すように、変換装置10は、物理的には、中央演算装置(CPU)210、入力装置220、出力装置230、主記憶装置(RAM/ROM)240、補助記憶装置250等を含むコンピュータシステムとして構成される。また、一時的な記憶回路としてCPU内に複数のレジスタ260を有する。   The conversion device 10 shown in FIG. 1 has the hardware configuration 20 shown in FIG. As shown in FIG. 2, the conversion device 10 physically includes a central processing unit (CPU) 210, an input device 220, an output device 230, a main storage device (RAM / ROM) 240, an auxiliary storage device 250, and the like. It is configured as a computer system. Further, the CPU has a plurality of registers 260 as a temporary storage circuit.

変換装置10の各機能は、図2に示す中央演算装置(CPU)210、主記憶装置(RAM/ROM)240等に所定のコンピュータソフトウェアを読み込ませることにより、中央演算装置(CPU)210の制御により入力装置220、出力装置230を動作させるとともに、主記憶装置(RAM/ROM)240、補助記憶装置250とデータの読み書きを行うことで実現される。   Each function of the conversion device 10 is controlled by controlling the central processing unit (CPU) 210 by reading predetermined computer software into a central processing unit (CPU) 210, a main storage device (RAM / ROM) 240, or the like shown in FIG. , The input device 220 and the output device 230 are operated, and data is read from and written to the main storage device (RAM / ROM) 240 and the auxiliary storage device 250.

次に、本実施形態に係る変換装置10の動作について説明する。図3は、本実施形態に係る変換装置10の動作を示すフローチャートである。図3に示すように変換装置10が行う処理は、情報取得処理ブロックB10、命令生成挿入処理ブロックB20、チェック処理ブロックB30の3つのブロックに大別される。なお、説明理解の容易性を考慮して、以下では、オペレーションシステムとしてLinux(登録商標)、プログラミング言語としてC言語、コンパイラとしてGNUコンパイラコレクション(以下、GCC)、及び、コンパイラが生成するファイル形式としてELFを使用するものとして説明するが、コンピュータが同様の挙動をとる環境であれば同じである。   Next, the operation of the conversion device 10 according to the present embodiment will be described. FIG. 3 is a flowchart illustrating the operation of the conversion device 10 according to the present embodiment. As shown in FIG. 3, the processing performed by the conversion device 10 is roughly divided into three blocks: an information acquisition processing block B10, an instruction generation insertion processing block B20, and a check processing block B30. In consideration of the ease of explanation, Linux (registered trademark) is used as an operation system, C language is used as a programming language, GNU compiler collection (hereinafter, GCC) is used as a compiler, and file formats generated by the compiler are used below. Although the description will be made assuming that the ELF is used, the same applies to an environment in which a computer behaves in a similar manner.

変換装置10は、例えば、変換対象プログラム及び変換対象プログラムにリンクされるプログラムをプロセス空間にロードした後に明示的に動作の開始を指示するなどによって、図3に示す動作を開始する。   The conversion device 10 starts the operation illustrated in FIG. 3 by, for example, explicitly instructing the start of the operation after loading the conversion target program and the program linked to the conversion target program into the process space.

図3に示すフローチャートに従って、本実施形態に係る変換装置10の動作について説明する。   The operation of the conversion device 10 according to the present embodiment will be described with reference to the flowchart shown in FIG.

変換装置10の動作の開始にあたっては、変換装置10に対して変換対象プログラムを指定する。変換装置10で起動する変換プログラムに引数として、変換対象プログラムであるすべての実行可能ファイルのディレクトリフルパス、変換対象プログラムであるすべての実行可能ファイルのソースファイルのディレクトリフルパスを与えることで指定する。また、実行可能ファイルにリンクされ、かつ変換対象プログラムであるすべての共有ライブラリについても、同様に、オブジェクトファイルのディレクトリフルパス、ソースファイルのディレクトリフルパスを引数として与える。このように引数を与える理由は、同一の共有ライブラリが複数の実行可能ファイルとリンクされる可能性があるため、共有ライブラリ内の関数に対するリターンアドレスチェック命令に不足が生じないようにするためである。   When the operation of the conversion device 10 is started, a conversion target program is designated for the conversion device 10. The conversion program started by the conversion apparatus 10 is specified by giving, as arguments, a directory full path of all executable files which are conversion target programs and a directory full path of source files of all executable files which are conversion target programs. Similarly, the full path of the object file and the full path of the source file are given as arguments for all the shared libraries that are linked to the executable file and are the conversion target programs. The reason for providing the arguments in this way is to prevent shortage of return address check instructions for functions in the shared library because the same shared library may be linked with multiple executable files. .

変換装置10は、図3のS301に示すように、前述の通り指定された変換対象プログラムであるすべての実行可能ファイルについて、順順次変換処理を行う。変換装置10の動作開始時に与えられる変換対象プログラムの実行可能なファイルが存在するディレクトリフルパス情報を引き継いで以下の処理を行う。まず、情報取得処理ブロックB10の処理から説明する。   As shown in S301 of FIG. 3, the conversion device 10 performs a sequential conversion process on all the executable files that are the conversion target programs specified as described above. The following processing is performed by inheriting the directory full path information in which the executable file of the conversion target program, which is provided at the start of the operation of the conversion apparatus 10 and exists. First, the processing of the information acquisition processing block B10 will be described.

関係情報生成部100が、関係情報生成処理(S303)を行う。関係情報生成処理(S303)は、変換対象プログラムを構成する実行可能ファイルまたは共有ライブラリなどのオブジェクトファイルについて、ソースファイルの存在するディレクトリと、個々のソースファイルに対応するオブジェクトファイル(以下、構成オブジェクトファイルという)と、シンボル名と、が互いに紐づく関係を示す関係情報をメモリマップに基づいて生成する処理である。   The relation information generation unit 100 performs a relation information generation process (S303). The relation information generation process (S303) includes, for an object file such as an executable file or a shared library that constitutes the conversion target program, a directory in which the source file exists, and an object file corresponding to each source file (hereinafter, a configuration object file This is a process of generating relationship information indicating a relationship between the symbol name and the symbol name based on the memory map.

図4は、以降の説明理解を容易とするために、関係情報生成部100が関係情報生成処理(S303)を行うことで生成する関係情報の例を模式的に示した図である。図4に示す関係情報を例にして関係情報生成処理(S303)について説明する。   FIG. 4 is a diagram schematically illustrating an example of the related information generated by the related information generating unit 100 performing the related information generating process (S303) in order to facilitate understanding of the following description. The relation information generation processing (S303) will be described using the relation information shown in FIG. 4 as an example.

関係情報生成部100は、メモリマップを取得する。メモリマップとは、オペレーティングシステムのカーネルにおいてプロセスの状態を示すデータ構造の情報をマッピングしたファイルである。メモリマップによってプロセス空間の各領域の正確な開始アドレスを得ることができる。例えば、Linux(登録商標)では、/procディレクトリ配下にプロセスIDごとに存在する。プロセスIDは、C言語ではgetpid関数によって取得できる。   The relation information generation unit 100 acquires a memory map. The memory map is a file in which information of a data structure indicating a state of a process is mapped in a kernel of the operating system. The exact starting address of each region of the process space can be obtained by the memory map. For example, in Linux (registered trademark), each process ID exists under the / proc directory. The process ID can be obtained by a getpid function in the C language.

図5に、メモリマップの例を示す。符号aに開始アドレスが、符号bに終了アドレスが、符号cにアクセス権限が、符号dにフルパスが示される。実行可能ファイル(符号e)と共有ライブラリ(符号f)は、いずれもアクセス権限(符号c)がr−xp(読み込み可、書き込み不可、実行可)であることから識別ができる。   FIG. 5 shows an example of the memory map. Reference numeral a indicates the start address, reference numeral b indicates the end address, reference numeral c indicates the access authority, and reference numeral d indicates the full path. Both the executable file (code e) and the shared library (code f) can be identified from the fact that the access authority (code c) is r-xp (readable, write-inhibited, executable).

関係情報生成部100は、取得したメモリマップからアクセス権限(符号c)がr−xpであるオブジェクトファイルについて、フルパス(符号d)を抽出して、図4に示すオブジェクトファイル配列を生成する。なお、アクセス権限(符号c)がr−xpであってもローダなどチェックの必要がないオブジェクトファイルについて、処理の効率化を図るために抽出対象から除外してもよい。   The relation information generation unit 100 extracts the full path (code d) from the acquired memory map for the object file whose access authority (code c) is r-xp, and generates the object file array shown in FIG. Note that even if the access right (code c) is r-xp, an object file such as a loader that does not need to be checked may be excluded from the extraction target in order to increase the processing efficiency.

関係情報生成部100は、生成したオブジェクトファイル配列40について、引数として与えられた変換対象プログラムである実行可能ファイルのディレクトリフルパス、ソースファイルのディレクトリフルパス、及び、実行可能ファイルにリンクされ、かつ、変換対象プログラムである共有ライブラリについてのオブジェクトファイルのディレクトリフルパス、ソースファイルのディレクトリフルパスを利用してソースファイルディレクトリと関係づける処理を行う。これにより、図4に示すオブジェクトファイル配列40とソースファイルディレクトリ41の関係づけが行われる。   The relation information generation unit 100 links the generated object file array 40 to the directory full path of the executable file which is the conversion target program given as an argument, the directory full path of the source file, and the executable file. Using the full path of the object file directory and the full path of the source file for the shared library that is the target program, a process of associating with the source file directory is performed. Thus, the object file array 40 and the source file directory 41 shown in FIG.

次に、関係情報生成部100は、図4に示す関係情報を生成するためにシンボル名調査を行う。関係情報生成部100は、図4に示すソースファイルディレクトリ41について、順次、図6にフローチャートで示されるシンボル名調査を実行する。ソースファイルディレクトリ41について、ディレクトリ内の要素がなくなるまで(S601)処理を実行する。   Next, the relation information generation unit 100 performs a symbol name check to generate the relation information shown in FIG. The relation information generation unit 100 sequentially performs a symbol name check shown in the flowchart of FIG. 6 on the source file directory 41 shown in FIG. The process is executed on the source file directory 41 until there are no more elements in the directory (S601).

S603の処理では、要素がディレクトリかどうかを判定する。要素がディレクトリであった場合には当該ディレクトリ内についてもシンボル名調査を行う必要があることから、当該ディレクトリについてのシンボル名調査処理(S605)を実行する。要素がディレクトリでない場合にはS607の判定処理に移行する。   In the process of S603, it is determined whether the element is a directory. If the element is a directory, it is necessary to check the symbol name also in the directory, so the symbol name checking process (S605) is performed for the directory. If the element is not a directory, the flow shifts to determination processing in S607.

S607の処理では、要素がオブジェクトファイルかどうかを判定する。ファイル名の拡張子が.oである場合、オブジェクトファイルと判定する。要素がオブジェクトファイルであると判定した場合には、構成オブジェクトファイル42として図4に示すようにソースファイルディレクトリ41と関係づける。その後、S609の処理に移行する。要素がオブジェクトファイルでないと判定した場合にはディレクトリ内の次の要素に移行する。   In the process of S607, it is determined whether the element is an object file. The file name extension is. If it is o, it is determined to be an object file. If it is determined that the element is an object file, the element is associated with the source file directory 41 as the constituent object file 42 as shown in FIG. After that, the processing shifts to S609. If it is determined that the element is not an object file, the process moves to the next element in the directory.

S609の処理では、シンボルを取得する。Linux(登録商標)ではnmコマンドによってシンボルを取得できる。取得したシンボル名43を図4に示すように構成オブジェクトファイル42と関係づける処理(S611)を行う。   In the process of S609, a symbol is obtained. In Linux (registered trademark), a symbol can be obtained by an nm command. A process (S611) for associating the acquired symbol name 43 with the configuration object file 42 as shown in FIG. 4 is performed.

ディレクトリ内の要素がなくなったら処理を終了する。   When there are no more elements in the directory, the process ends.

関係情報生成部100による関係情報生成処理(S303)が完了すると、図4に示す関係情報が生成される。   When the related information generating process (S303) by the related information generating unit 100 is completed, the related information illustrated in FIG. 4 is generated.

次に、ロードアドレス算出命令挿入部110が、ロードアドレス算出命令挿入処理(S305)を行う。ロードアドレス算出命令挿入処理(S305)は、変換対象プログラムの実行開始直後に、変換対象プログラムからロードアドレス算出命令を呼び出すことができるように変換対象プログラムにコードを挿入する処理である。   Next, the load address calculation instruction insertion unit 110 performs load address calculation instruction insertion processing (S305). The load address calculation instruction insertion process (S305) is a process of inserting a code into the conversion target program so that the load target calculation instruction can be called from the conversion target program immediately after the execution of the conversion target program starts.

位置独立コード化された共有ライブラリなどはロードされないとアドレスが確定しない。このため、ロードアドレス算出命令挿入部110は、変換対象プログラムの実行開始直後に、変換対象プログラムから、ロードアドレス算出命令を呼び出すことができるように変換対象プログラムにコードを挿入することでロード時の開始アドレスを取得できるようにする。   The address of a shared library that is position-independently coded cannot be determined unless it is loaded. For this reason, the load address calculation instruction insertion unit 110 inserts a code into the conversion target program so that the load address calculation instruction can be called from the conversion target program immediately after the execution of the conversion target program is started. Enable to get start address.

図7は、ロードアドレス算出命令挿入処理を示すフローチャートである。図7に示すフローチャートに従って、ロードアドレス算出命令挿入処理について説明する。   FIG. 7 is a flowchart showing the load address calculation instruction insertion processing. The load address calculation instruction insertion processing will be described with reference to the flowchart shown in FIG.

S701の処理では、図4に示すオブジェクトファイル配列の第一要素に対応するソースファイルディレクトリを取得する。メモリマップでは、実行可能ファイルが必ず第一要素となっているため、オブジェクトファイル配列の第一要素が必ず実行可能ファイルに対応する。S701の処理が終了するとS703の処理に移行する。   In the process of S701, a source file directory corresponding to the first element of the object file array shown in FIG. 4 is obtained. In the memory map, since the executable file is always the first element, the first element of the object file array always corresponds to the executable file. When the processing in S701 ends, the flow shifts to the processing in S703.

S703の処理では、取得したオブジェクトファイル配列の第一要素に対応するソースファイルディレクトリについてディレクトリ内の要素がなくなるまで順次処理を行う。   In the process of S703, the source file directory corresponding to the first element of the obtained object file array is sequentially processed until there are no more elements in the directory.

S705の処理では、要素がディレクトリかどうかを判定する。要素がディレクトリであった場合には当該ディレクトリ内についてもロードアドレス算出命令挿入処理を行う必要があることから、当該ディレクトリについてのロードアドレス算出命令挿入処理(S707)を実行する。要素がディレクトリでない場合にはS709の判定処理に移行する。   In the process of S705, it is determined whether the element is a directory. If the element is a directory, the load address calculation instruction insertion processing needs to be performed also in the directory, so the load address calculation instruction insertion processing for the directory (S707) is executed. If the element is not a directory, the flow shifts to determination processing in S709.

S709の処理では、要素がソースファイルかどうかを判定する。例えば、C言語で書かれたソースファイルは拡張子が、「.C」のファイルである。要素がソースファイルでなければ次の要素に移行する。要素がソースファイルならばファイルをオープンしてS711の処理に移行する。   In the process of S709, it is determined whether the element is a source file. For example, a source file written in the C language is a file having an extension “.C”. If the element is not a source file, move to the next element. If the element is a source file, the file is opened and the process proceeds to S711.

S711の処理では、ソースファイルについて終端まで順次読み込んでmain関数を見つける(S713)。main関数が見つかった場合には、ロードアドレス算出命令を呼び出すコードをmain関数内の冒頭(ソースファイルのmain関数が記述された直後の行)に記述(S715)する。これにより、変換後のプログラム実行時にmain関数が呼び出されると、まず初めにロードアドレス算出命令が呼び出される。   In the processing of S711, the main function is sequentially read to the end of the source file to find a main function (S713). If the main function is found, the code for calling the load address calculation instruction is described at the beginning of the main function (line immediately after the main function of the source file is described) (S715). Thus, when the main function is called during execution of the converted program, the load address calculation instruction is called first.

S715の処理では、main関数にロードアドレス算出命令を呼び出すコードを新たに記述した。S717の処理では、この新たに呼び出されるロードアドレス算出命令の実体を含むソースファイルと共にコンパイルとリンクを行う必要があるため、Makefileの書き換えを行う。以上が、情報取得処理ブロックB10の処理である。   In the process of S715, a code for calling the load address calculation instruction in the main function is newly described. In the process of S717, the Makefile is rewritten because it is necessary to compile and link with the source file including the substance of the newly called load address calculation instruction. The above is the processing of the information acquisition processing block B10.

ロードアドレス算出命令挿入部110によるロードアドレス算出命令挿入処理(S305)が完了すると、変換装置10は、コンパイラ120に書き換えたMakefileを使ってコンパイル(S307)させ、実行可能ファイルを作成する。この時、変換装置10は、後続の命令生成挿入処理ブロックB20で使用するアセンブリファイルとして、図4のすべてのソースファイルディレクトリ41内のソースファイルに対してアセンブリファイルの出力を行なう。   When the load address calculation instruction insertion processing (S305) by the load address calculation instruction insertion unit 110 is completed, the conversion device 10 compiles (S307) using the rewritten Makefile by the compiler 120 to create an executable file. At this time, the conversion device 10 outputs an assembly file to the source files in all the source file directories 41 of FIG. 4 as an assembly file used in the subsequent instruction generation / insertion processing block B20.

ここで、図3の処理フローから離れて、変換後のプログラム実行時におけるロードアドレス算出命令の動作ついて説明する。ロードアドレス算出命令は、変換対象プログラムの開始アドレス及び変換対象プログラムにリンクされるプログラムの開始アドレスを算出し、アドレスの低い順に1つの文字列に連結してファイルに出力し、このファイルに記載された文字列を読み込み可能、書き込み不可としてプロセス空間に新たなメモリ領域として保存し、このメモリ領域の開始アドレスを静的変数に格納する。   Here, apart from the processing flow of FIG. 3, the operation of the load address calculation instruction at the time of executing the converted program will be described. The load address calculation instruction calculates the start address of the program to be converted and the start address of the program linked to the program to be converted, concatenates them into one character string in ascending order of address, and outputs the result to a file. The character string that has been read is stored as a new memory area in the process space as readable and unwritable, and the start address of this memory area is stored in a static variable.

図8は、ロードアドレス算出命令によって実行される処理フローである。ロードアドレス算出命令を呼び出すコードはmain関数の直後に記述されるため、変換後のプログラム実行直後にロードアドレス算出命令によって図8に示す処理フローが実行される。   FIG. 8 is a processing flow executed by the load address calculation instruction. Since the code for calling the load address calculation instruction is described immediately after the main function, the processing flow shown in FIG. 8 is executed by the load address calculation instruction immediately after execution of the converted program.

S801の処理では、起動したプロセスのプロセスIDを取得する。プロセスIDは、C言語ではgetpid関数によって取得できる。S801の処理が終了するとS803の処理に移行する。   In the process of S801, the process ID of the started process is acquired. The process ID can be obtained by a getpid function in the C language. When the processing in S801 ends, the flow shifts to the processing in S803.

S803の処理では、取得したプロセスIDのメモリマップを取得する。メモリマップは/procディレクトリ配下にプロセスIDごとに存在する。S803の処理が終了するとS805の処理に移行する。   In the process of S803, a memory map of the obtained process ID is obtained. A memory map exists for each process ID under the / proc directory. When the processing in S803 ends, the flow shifts to the processing in S805.

S805の処理では、取得したメモリマップについて1行目から順に取得して、アクセス権限がr−xp(読み込み可、書き込み不可、実行可)であるかどうか判定(S807)することで、実行可能ファイルと共有ライブラリを抽出する。   In the process of S805, the acquired memory map is acquired in order from the first line, and it is determined whether the access right is r-xp (readable, writable, executable) (S807). And extract the shared library.

S809の処理では、r−xp行の開始アドレス(図5符号aを参照)を取得し、取得した開始アドレスを連結した文字列を生成する。後の処理で生成した文字列から開始アドレスが復元できるように各開始アドレスのバイト数を統一する。例えば、バイト数については、0を埋めることで16バイトにアドレスを修正する。また、バイト順(エンディアン)がプロセッサやプラットフォームによって異なるため、環境にあわせた文字列を生成する。エンディアンの種別についてはELFヘッダに情報が記述されている。S809の処理がメモリマップのすべてのr−xp行について終了するとS811の処理に移行する。   In the processing of S809, the start address of the r-xp row (see reference symbol a in FIG. 5) is obtained, and a character string in which the obtained start addresses are concatenated is generated. The number of bytes of each start address is unified so that the start address can be restored from a character string generated in a later process. For example, with regard to the number of bytes, the address is corrected to 16 bytes by filling in 0s. Since the byte order (endian) differs depending on the processor and platform, a character string is generated according to the environment. Information about the type of endian is described in the ELF header. When the processing in S809 ends for all r-xp rows in the memory map, the processing shifts to S811.

S811の処理では、開始アドレスを結合した文字列を、改ざんされないようにmmap関数を使用して読み取り専用でメモリ領域に書き込む。開始アドレス格納変数として静的変数をひとつ定義して、その静的変数に読み取り専用で文字列を書き込んだメモリ領域の先頭のアドレスを格納する。   In the process of S811, the character string combined with the start address is read-only written to the memory area using the mmap function so as not to be falsified. One static variable is defined as a start address storage variable, and the start address of a memory area in which a character string is written to the static variable in a read-only manner is stored.

開始アドレス格納変数で指示されるメモリ領域に読み込み専用で書き込まれた文字列の先頭から16バイトごとに各々のオブジェクトの開始アドレスが記述されているので、目的の位置から文字列を読み込むことで目的とするオブジェクトの開始アドレスを取得することができる。   Since the start address of each object is described every 16 bytes from the beginning of the character string written read-only in the memory area specified by the start address storage variable, reading the character string from the target position Can be obtained.

このようにロードアドレス算出命令によって、変換対象プログラムの開始アドレス及び変換対象プログラムにリンクされる共有ライブラリの開始アドレスをメモリマップに基づいて算出し、保持する。   In this way, the load address calculation instruction calculates and holds the start address of the conversion target program and the start address of the shared library linked to the conversion target program based on the memory map.

次に、図3に示す命令生成挿入処理ブロックB20の処理についての説明に移る前に、以降の説明理解の容易性を考慮して、変換装置10によって変換された後の変換対象プログラムの動作と命令生成挿入処理ブロックB20のS309からS313の処理との関係について概要を説明する。   Next, before proceeding to the description of the processing of the instruction generation / insertion processing block B20 shown in FIG. 3, the operation of the conversion target program after conversion by the conversion device 10 is described in consideration of the following description. The relationship between the instruction generation and insertion processing block B20 and the processing from S309 to S313 will be briefly described.

図9は、変換された後の変換対象プログラムの動作の概要を説明する図である。図9では、関数myfuncが呼び出された場合を例示している。   FIG. 9 is a diagram for explaining an outline of the operation of the conversion target program after the conversion. FIG. 9 illustrates a case where the function myfunc is called.

図9に沿って変換された後の変換対象プログラムの動作について概要を説明する。呼び出し元のアセンブリ言語で記述されたソースコード(以下、アセンブリコードという)でcall myfuncで関数myfuncが呼び出されると、呼び出し先アセンブリファイルの関数myfuncに処理が移る。呼び出し先アセンブリファイルでは、関数myfuncの処理終了後に呼び出し元に戻るためのret命令がリターンアドレスチェック命令へのjump命令(903)に書き換わっている。このため、関数myfuncの処理が終了すると、同じ呼び出し先アセンブリファイルに記述されたリターンアドレスチェック命令(905)に処理が移る。リターンアドレスチェック命令では、チェックロジックに基づいてリターン先が正しいかどうかを判定し、正しくないと判定した場合にはプロセスを終了し、正しいと判定した場合には呼び出し元アセンブリファイルのcall命令の次の行に記述された識別ラベルにジャンプする。   An outline of the operation of the conversion target program after the conversion will be described with reference to FIG. When the function myfunc is called by the call myfunc in the source code described in the caller's assembly language (hereinafter, referred to as assembly code), the processing shifts to the function myfunc in the callee assembly file. In the callee assembly file, the ret instruction for returning to the caller after the processing of the function myfunc is completed has been rewritten to the jump instruction (903) to the return address check instruction. Therefore, when the processing of the function myfunc ends, the processing shifts to the return address check instruction (905) described in the same callee assembly file. In the return address check instruction, it is determined whether the return destination is correct based on the check logic. If the return destination is not correct, the process is terminated. If it is determined that the return destination is correct, the process is executed next to the call instruction in the caller assembly file. Jump to the identification label described in the line.

変換された後の変換対象プログラムの動作と命令生成挿入処理ブロックB20のS309からS313の処理との関係について図9を用いて概要を説明する。命令生成挿入処理ブロックB20の処理では、前述の図9に示す動作を行うように変換対象プログラムのアセンブリコードを書き換えることでプログラムを変換する。識別ラベル生成挿入処理(S309)は、呼び出し元アセンブリファイルから関数呼び出し命令を検出し、関数呼び出し命令が呼び出した関数の処理が終了した後にリターンすべき場所を特定するための識別ラベル(901)を生成し、検出した関数呼び出し命令と次の命令との間に識別ラベル(901)を挿入する。リターン命令書き換え処理(S311)は、呼び出し先アセンブリファイルからリターン命令を検出し、検出したリターン命令を、リターンアドレスチェック命令へ分岐する命令(903)に書き換える。リターンアドレスチェック命令生成挿入処理(S313)は、リターンアドレスチェック命令(905)を生成し、呼び出し先アセンブリファイルに挿入する。   The outline of the relationship between the operation of the conversion target program after the conversion and the processing of S309 to S313 of the instruction generation and insertion processing block B20 will be described with reference to FIG. In the processing of the instruction generation / insertion processing block B20, the program is converted by rewriting the assembly code of the conversion target program so as to perform the operation shown in FIG. The identification label generation / insertion processing (S309) detects a function call instruction from the caller assembly file and adds an identification label (901) for specifying a place to return to after the processing of the function called by the function call instruction is completed. The identification label (901) is inserted between the generated and detected function call instruction and the next instruction. The return instruction rewriting process (S311) detects a return instruction from the callee assembly file, and rewrites the detected return instruction into an instruction (903) that branches to a return address check instruction. The return address check instruction generation / insertion processing (S313) generates a return address check instruction (905) and inserts it into the callee assembly file.

前述のように、本実施例では、呼び出し先アセンブリファイルにリターンアドレスチェック命令を記述することで、リターン先が正しいかどうかの判定を実現している。しかし、呼び出される関数が標準関数の場合、標準関数はバイナリで提供されるので、直接アセンブリファイルにリターンアドレスチェック命令を記述することができない。そこで、第1実施形態では、変換対象プログラムが使用する標準関数については、公開されているソースコードを参考にして同じ動作をする自作した標準関数を新たな共有ライブラリとして配置することで、直接アセンブリファイルにリターンアドレスチェック命令を記述できるようにする。この方法によれば、リターンアドレスの改ざんを完全に防ぐことができる。なお、バイナリで提供される標準関数をそのまま使用する実施形態を第2実施形態として後述する。   As described above, in the present embodiment, it is possible to determine whether the return destination is correct by describing the return address check instruction in the callee assembly file. However, when the function to be called is a standard function, the standard function is provided in binary, so that the return address check instruction cannot be directly described in the assembly file. Therefore, in the first embodiment, the standard functions used by the conversion target program are directly assembled by arranging a self-made standard function that performs the same operation as a new shared library with reference to the published source code. Enables you to write a return address check instruction in a file. According to this method, falsification of the return address can be completely prevented. An embodiment in which a standard function provided in binary is used as it is will be described later as a second embodiment.

図3に戻って、命令生成挿入処理ブロックB20の処理について説明する。識別ラベル生成挿入部130が、識別ラベル生成挿入処理(S309)を行う。識別ラベル生成挿入処理(S309)は、変換対象プログラムに含まれる関数呼び出し命令を検出し、関数呼び出し命令が呼び出した関数の処理が終了した後にリターンすべき場所を特定するための識別ラベルを生成し、検出した関数呼び出し命令と次の命令との間に識別ラベルを挿入する処理である。   Returning to FIG. 3, the processing of the instruction generation / insertion processing block B20 will be described. The identification label generation and insertion unit 130 performs an identification label generation and insertion process (S309). The identification label generation / insertion process (S309) detects a function call instruction included in the conversion target program, and generates an identification label for specifying a place to return to after the processing of the function called by the function call instruction is completed. This is a process of inserting an identification label between the detected function call instruction and the next instruction.

図10は、識別ラベル生成挿入処理(S309)とリターン命令書き換え処理(S311)を示すフローチャートである。アセンブリコードを読み込んで、図10のフローチャートに示す処理に従ってアセンブリコードの書き換えを行う。まず、図10に沿って識別ラベル生成挿入処理(S309)について説明する。   FIG. 10 is a flowchart showing the identification label generation and insertion processing (S309) and the return instruction rewriting processing (S311). The assembly code is read, and the assembly code is rewritten according to the processing shown in the flowchart of FIG. First, the identification label generation and insertion processing (S309) will be described with reference to FIG.

識別ラベル生成挿入部130は、識別ラベル生成挿入処理(S309)を行う。識別ラベル生成挿入処理(S309)は、アセンブリファイルごとに実行される。S1001の処理では、アセンブリファイルの1行目から末尾まで順次以下の処理を行う。   The identification label generation and insertion unit 130 performs an identification label generation and insertion process (S309). The identification label generation and insertion processing (S309) is executed for each assembly file. In the processing of S1001, the following processing is sequentially performed from the first line to the end of the assembly file.

S1003の処理は、変換対象プログラムに含まれる関数呼び出し命令を検出するためにcall命令を発見する処理である。call命令を発見した場合にはS1005の処理に移行する。   The process of S1003 is a process of finding a call instruction to detect a function call instruction included in the conversion target program. If a call instruction is found, the flow shifts to the process of S1005.

S1005の処理は、S1003の処理で発見したcall命令とcall命令の次の行に呼び出した関数の処理が終了した後にリターンすべき場所を特定するための識別ラベルを生成してアセンブリコードとして出力する。   In the processing of S1005, an identification label for specifying a place to return to after the processing of the call instruction found in the processing of S1003 and the function called on the line following the call instruction is completed is generated and output as an assembly code. .

図11は、識別ラベル出力処理(S1005)を示すフローチャートである。アセンブリコードを生成することで書き換え処理を行う。図11では、図4に示す関数print_msgがcall命令によって呼び出される場合を例として説明する。図4で、関数print_msgは、シンボル名print_msg、構成オブジェクトファイルsample_1.oに属し、ソースディレクトリ/usr/local/src/sample_1/に存在する。   FIG. 11 is a flowchart showing the identification label output processing (S1005). The rewriting process is performed by generating the assembly code. In FIG. 11, a case where the function print_msg shown in FIG. 4 is called by a call instruction will be described as an example. In FIG. 4, the function print_msg is composed of a symbol name print_msg, a configuration object file sample_1. o and exists in the source directory / usr / local / src / sample_1 /.

S1101の処理は、リターン元の識別ラベルを生成する。識別ラベルの名づけは、識別ができればルールは問わない。ここでは、例示として、リターン元識別ラベルであることを示す共通の文字列「.ATTC_RET_LB」、存在するソースディレクトリ/usr/local/src/sample_1/をハッシュ化した文字列「35xqh754」、ソースファイル名「sample_1」及び連番「$2」を結合して識別ラベルを生成している。同じアセンブリコードで同じ関数が複数回呼び出されることがあるが、同じ関数であってもリターン元は異なるため、識別ラベル名が重複しないように処理する。図11の例示では識別ラベルに連番を付与して識別ラベル名が重複しないようしている。S1101の処理が終了するとS1103の処理に移行する。   In the process of S1101, a return source identification label is generated. The rules for naming the identification labels are not limited as long as they can be identified. Here, as an example, a common character string “.ATTC_RET_LB” indicating a return source identification label, a character string “35xqh754” obtained by hashing an existing source directory / usr / local / src / sample_1 /, a source file name The identification label is generated by combining "sample_1" and the serial number "$ 2". The same function may be called multiple times in the same assembly code. However, since the return source is different even for the same function, processing is performed so that the identification label name is not duplicated. In the example of FIG. 11, serial numbers are assigned to the identification labels so that the identification label names do not overlap. When the processing in S1101 ends, the flow shifts to the processing in S1103.

S1103とS1105の処理では、識別ラベルの挿入処理を行う。S1101の処理で生成した識別ラベルを、関数を呼び出すcall命令と次の命令との間に挿入する。S1105の処理が終了するとS1107の処理に移行する。   In the processing of S1103 and S1105, an identification label insertion processing is performed. The identification label generated in the process of S1101 is inserted between the call instruction for calling the function and the next instruction. When the processing in S1105 ends, the flow shifts to the processing in S1107.

S1107の処理は、リターン元識別ラベルファイルを生成して、関数名(1109)、識別ラベル名(1111)、アドレス値(1113)を書き込んで保存する。リターン元識別ラベルファイルの各行は、関数名でソート(S1107)しておく。S1107の処理の段階では、アドレス値(1113)には初期値として、一律で0000000000000000を書き込む。なお、この値は後述の識別ラベルアドレス取得処理(S315)において、識別ラベルのアドレスが取得されると更新される。これによって、リターン元識別ラベルファイルにアドレス値(1113)として保持される。   In the process of S1107, a return source identification label file is generated, and the function name (1109), the identification label name (1111), and the address value (1113) are written and stored. Each line of the return source identification label file is sorted by function name (S1107). In the processing stage of S1107, 0000000000000000 is uniformly written as the initial value in the address value (1113). This value is updated when the address of the identification label is acquired in the identification label address acquisition processing (S315) described later. As a result, the address value (1113) is held in the return source identification label file.

次に、図10に沿ってリターン命令書き換え処理(S311)について説明する。リターン命令書き換え部140は、リターン命令書き換え処理(S311)を行う。リターン命令書き換え処理(S311)は、アセンブリファイルごとに実行される。S1001の処理では、アセンブリファイルの1行目から末尾まで順次処理を行う。   Next, the return instruction rewriting process (S311) will be described with reference to FIG. The return instruction rewriting unit 140 performs a return instruction rewriting process (S311). The return instruction rewriting process (S311) is executed for each assembly file. In the processing of S1001, the processing is sequentially performed from the first line to the end of the assembly file.

S1007の処理は、変換対象プログラムに含まれるリターン命令を検出するためにret命令を発見する処理である。ret命令を発見した場合にはS1009の処理に移行する。   The process of S1007 is a process of finding a ret instruction to detect a return instruction included in the conversion target program. If a ret instruction is found, the flow shifts to the processing of S1009.

S1009の処理は、検出したリターン命令をリターンアドレスチェック命令へ分岐する命令に書き換える。具体的には、図9で示したように、ret命令を同じソースファイルに記述されたリターンアドレスチェック命令のラベルにジャンプするjmp命令に書き換える。   The process of S1009 rewrites the detected return instruction to an instruction that branches to a return address check instruction. Specifically, as shown in FIG. 9, the ret instruction is rewritten to a jmp instruction that jumps to the label of the return address check instruction described in the same source file.

リターンアドレスチェック命令は、呼び出される関数ごとに独立して個別に存在し、チェックするリターン元識別ラベルごとのチェックロジックが記述されている。このため、リターンアドレスチェック命令のラベル名は呼び出される関数ごとに重複しないように付与する必要がある。本実施例では、図11に示すリターン元識別ラベルファイルの連番を除いた識別ラベル名(1111)と関数名(1109)を結合した文字列をリターンアドレスチェック命令のラベル名として付与している。具体的には、図11で関数print_msgに対応するリターンアドレスチェック命令のラベル名は、ATTC_RET_LB_35xqh754_sample_1$print_msgとなる。   The return address check instruction exists independently for each function to be called, and describes a check logic for each return source identification label to be checked. For this reason, the label name of the return address check instruction needs to be assigned so as not to be duplicated for each called function. In this embodiment, a character string obtained by combining the identification label name (1111) excluding the serial number of the return source identification label file shown in FIG. 11 and the function name (1109) is given as the label name of the return address check instruction. . Specifically, the label name of the return address check instruction corresponding to the function print_msg in FIG. 11 is ATTC_RET_LB_35xqh754_sample_1 @ print_msg.

S1011の処理は、アセンブリコードで、call命令、ret命令のいずれでもない行についてはそのまま出力する。アセンブリファイルの末尾まで処理を行って、識別ラベル生成挿入処理(S309)とリターン命令書き換え処理(S311)が終了する。   In the process of S1011, a line that is neither the call instruction nor the ret instruction in the assembly code is output as it is. The processing is performed up to the end of the assembly file, and the identification label generation and insertion processing (S309) and the return instruction rewriting processing (S311) are completed.

リターンアドレスチェック命令生成挿入部150は、リターンアドレスチェック命令生成挿入処理(S313)を行う。リターンアドレスチェック命令生成挿入処理(S313)は、変換対象プログラムにリターンアドレスチェック命令を生成し、挿入する処理を行う。   The return address check instruction generation / insertion unit 150 performs a return address check instruction generation / insertion process (S313). The return address check instruction generation and insertion processing (S313) performs processing of generating and inserting a return address check instruction in the conversion target program.

図12は、リターンアドレスチェック命令生成挿入処理(S313)を示すフローチャートである。関係情報生成部100が生成した関係情報(図4参照)に基づいて、すべてのソースファイルディレクトリ41について(S1201)、関係づけられた構成オブジェクトファイル42に対応(S1203)するアセンブリファイルに含まれるシンボル名43を引数として(S1205)、引数としたシンボル名に対応する関数についてのリターンアドレスチェック命令を生成して、当該関数が含まれるアセンブリファイルに出力(図9を参照)する。   FIG. 12 is a flowchart showing the return address check instruction generation and insertion processing (S313). Based on the relation information generated by the relation information generation unit 100 (see FIG. 4), for all the source file directories 41 (S1201), the symbols included in the assembly file corresponding to the related configuration object file 42 (S1203) With the name 43 as an argument (S1205), a return address check instruction for a function corresponding to the symbol name as an argument is generated and output to an assembly file including the function (see FIG. 9).

図13は、S1207の処理であるリターンアドレスチェック命令の生成について詳細に説明するフローチャートである。リターンアドレスチェック命令は、当該アセンブリファイル内のシンボル名に対応する関数ごとに生成されるが、リターン元は複数存在するため、リターン元識別ラベルファイル(図11参照)の識別ラベルごとに判定を行うチェックロジックで構成される。具体的には、リターンアドレスチェック命令は、変換後のプログラム実行時において、レジスタAにリターン命令がリターン先として指し示すアドレスを、レジスタBにリターンすべきアドレス(算出して保持している変換対象プログラム実行時の識別ラベルの絶対アドレス)を、それぞれ退避してレジスタAとレジスタBと一致しているか判定を行うことで、リターンアドレスの改ざんを検知する。   FIG. 13 is a flowchart illustrating in detail the generation of the return address check instruction, which is the process of S1207. The return address check instruction is generated for each function corresponding to the symbol name in the assembly file. However, since there are a plurality of return sources, a determination is made for each identification label in the return source identification label file (see FIG. 11). Consists of check logic. More specifically, the return address check instruction, when executing the converted program, stores the address indicated by the return instruction as the return destination in the register A, and the address to be returned in the register B (the calculated and held conversion target program). The falsification of the return address is detected by determining whether the absolute address of the identification label at the time of execution is the same as the register A and the register B, respectively.

図13に沿ってリターンアドレスチェック命令の生成について説明する。前述の通り、リターンアドレスチェック命令生成挿入処理(S313)は、関係情報生成部100が生成した関係情報に基づいたアセンブリファイルに含まれるシンボル名を引数としてもつ。ここでは、引数のシンボル名をprint_msgとして説明を進める。S1301の処理は、識別ラベル生成挿入部130が生成したリターン元識別ラベルファイル(図11参照)の要素について終端まで順次以下の処理をおこなう。   The generation of the return address check instruction will be described with reference to FIG. As described above, the return address check instruction generation and insertion processing (S313) has as an argument the symbol name included in the assembly file based on the relation information generated by the relation information generation unit 100. Here, the description proceeds with the symbol name of the argument being print_msg. In the process of S1301, the following processes are sequentially performed on the elements of the return source identification label file (see FIG. 11) generated by the identification label generation / insertion unit 130 up to the end.

S1303の処理では、リターン元識別ファイルに記述された関数名1109と引数としてシンボル名で与えられた関数名が一致するか判断する。一致しない場合は、リターン元識別ファイルの次の行に移って処理を繰り返す。一致する場合は、S1305の処理に移行する。   In the process of S1303, it is determined whether the function name 1109 described in the return source identification file matches the function name given as a symbol name as an argument. If they do not match, the process moves to the next line in the return source identification file and repeats the process. If they match, the process moves to S1305.

S1305の処理では、引数としてシンボル名で与えられた関数名が、リターン元識別ファイルに記述された関数名として最初に出現した行であるかどうかを判定する。リターン元識別ラベルファイルは関数名でソートされているので、順次、ファイルを読み込むことで、関数名が最初に出現したかどうか判定できる。図11に示すリターン元識別ファイルでは、関数名print_msgは4行に渡って記述されているが、関数名でソート済みなので、リターン元識別ファイルの要素の2行目が関数名print_msgの最初に出現した行となる。S1305の処理で、引数としてシンボル名で与えられた関数名が、リターン元識別ファイルに記述された関数名として最初に出現した行であると判定されると、S1307の処理に移行する。   In the process of S1305, it is determined whether or not the function name given by the symbol name as the argument is the first line that appears as the function name described in the return source identification file. Since the return source identification label file is sorted by the function name, by sequentially reading the file, it can be determined whether the function name appears first. In the return source identification file shown in FIG. 11, the function name print_msg is described over four lines, but since the function names have been sorted, the second line of the element of the return source identification file appears first in the function name print_msg. Line. If it is determined in step S1305 that the function name given as a symbol name as an argument is the first line that appears as the function name described in the return source identification file, the process advances to step S1307.

S1307の処理は、リターン元識別ファイルに記述された関数のリターンアドレスチェック命令であること示すラベルを出力する。前述の通り、図11の関数print_msgに対応するリターンアドレスチェック命令のラベル名は、ATTC_RET_LB_35xqh754_sample_1$print_msgとなる。S1309からの処理で、このラベルのあとに当該関数についてリターン元識別ラベルごとのチェックロジックが記述される。S1307の処理が終了するとS1309の処理に移行する。   The process of S1307 outputs a label indicating that the instruction is a return address check instruction of a function described in the return source identification file. As described above, the label name of the return address check instruction corresponding to the function print_msg of FIG. 11 is ATTC_RET_LB_35xqh754_sample_1 @ print_msg. In the processing from S1309, a check logic for each return source identification label is described for the function after this label. When the processing in S1307 ends, the flow shifts to the processing in S1309.

S1309の処理は、スタックをレジスタAに退避する命令を出力する。変換後のプログラムが起動した場合、リターンアドレスチェック命令が呼び出されたタイミングでスタックポインタが指しているのはリターンアドレスになるので、リターンアドレスがレジスタAに格納される。S1309の処理が終了するとS1311の処理に移行する。   The process of S1309 outputs an instruction to save the stack to the register A. When the converted program is started, the return address is stored in the register A because the stack pointer points to the return address when the return address check instruction is called. When the processing in S1309 ends, the flow shifts to the processing in S1311.

S1311からS1325の処理は、変換後のプログラム実行時において、レジスタAに格納したリターンアドレスと対比するためのリターンすべきアドレス(算出して保持している変換対象プログラム実行時の識別ラベルの絶対アドレス)をレジスタBに格納する命令を出力する。事前準備処理として、変換装置10は、リターン元識別ファイル中の識別ラベルのアドレスを、nmコマンドにより問い合わせて取得する。この際、取得できるアドレスは、識別ラベルが記述されたファイルのELFヘッダのエントリポイントに記述された値が相対アドレスの場合は位置独立コード化されたファイルであってアドレスは相対アドレス(オフセット値)となる。従って、変換後のプログラム実行時でのチェックタイミングにおいて、変換後のプログラムが絶対アドレスを演算で求めるようにチェックロジックを生成する。   The processing from S1311 to S1325 is performed when the post-conversion program is executed, the return address to be compared with the return address stored in the register A (the absolute address of the calculated and held identification label at the time of execution of the conversion target program). ) Is output to the register B. As a preparatory process, the conversion device 10 inquires and acquires the address of the identification label in the return source identification file using the nm command. At this time, if the value described in the entry point of the ELF header of the file in which the identification label is described is a relative address, the address that can be obtained is a position-independent coded file, and the address is a relative address (offset value). Becomes Therefore, the check logic is generated so that the converted program obtains the absolute address by the calculation at the check timing when the converted program is executed.

S1311の処理は、識別ラベルが記述されたオブジェクトファイルが位置独立コード化されているかどうかを判定する。具体的には識別ラベルが記述された実行可能ファイル又は共用ライブラリのELFヘッダを参照し、エントリポイントが相対アドレスであるかどうかを判定する。相対アドレスかどうかは、エントリポイントが16進数で,400000より小さいかどうかで判定できる。S1311の処理で、識別ラベルが記述されたオブジェクトファイルが位置独立コード化されていると判定された場合、S1313の処理に移行する。 The process of S1311 determines whether the object file in which the identification label is described is position-independent coded. Specifically, it is determined whether the entry point is a relative address by referring to the ELF header of the executable file or the shared library in which the identification label is described. Whether the address is a relative address can be determined based on whether the entry point is smaller than 4,000,000 in hexadecimal. If it is determined in step S1311 that the object file in which the identification label is described is encoded in position-independent manner, the process proceeds to step S1313.

S1313からS1319の処理は、識別ラベルが位置独立コード化されたオブジェクトファイル内に存在する場合の処理である。この場合、識別ラベルのアドレスはオフセット値である。よって、識別ラベルの絶対アドレスは、識別ラベルが記述されたロードされたオブジェクトファイルの開始アドレスに、リターン元識別ファイル中の識別ラベルのオフセット値を加算することで求められる。   The processing from S1313 to S1319 is processing when the identification label exists in the position-independent coded object file. In this case, the address of the identification label is an offset value. Therefore, the absolute address of the identification label is obtained by adding the offset value of the identification label in the return source identification file to the start address of the loaded object file in which the identification label is described.

S1313からS1319の処理について詳細に説明する。S1313からS1317の処理は、識別ラベルが記述されたオブジェクトファイルの開始アドレスの絶対アドレスを算出してレジスタBに格納する命令を出力する。   The processing from S1313 to S1319 will be described in detail. The processing from S1313 to S1317 outputs an instruction to calculate the absolute address of the start address of the object file in which the identification label is described and store the absolute address in the register B.

変換後のプログラム実行時には、実行直後に、ロードアドレス算出命令(図8)によって、変換対象プログラムの開始アドレス及び変換対象プログラムにリンクされる共有ライブラリの開始アドレスがメモリマップに基づいて取得され、これら開始アドレスを連結した文字列が読み取り専用でメモリ領域に書き込まれる。そして、このメモリ領域の先頭アドレスが開始アドレス格納変数に保持される。識別ラベルのアドレスがオフセット値である場合、リターンアドレスチェック命令生成挿入部150は、ロードアドレス算出命令(図8)によって取得され、保持されているアドレスを使ってリターンアドレスのチェックを行う命令を生成して挿入する。   At the time of executing the converted program, immediately after the execution, the load address calculation instruction (FIG. 8) obtains the start address of the conversion target program and the start address of the shared library linked to the conversion target program based on the memory map. A character string obtained by concatenating the start addresses is written to the memory area in a read-only manner. Then, the start address of this memory area is held in the start address storage variable. When the address of the identification label is an offset value, the return address check instruction generation / insertion unit 150 generates an instruction for checking the return address using the address acquired and held by the load address calculation instruction (FIG. 8). And insert.

S1313の処理は、開始アドレス格納変数の参照先アドレス(ロードされたオブジェクトファイルの開始アドレスを連結した文字列が書き込まれているメモリ領域の先頭アドレス)をレジスタBに転送する命令を出力する。   The process of S1313 outputs an instruction to transfer to the register B the reference address of the start address storage variable (the start address of the memory area in which the character string in which the start address of the loaded object file is linked) is written.

S1315の処理は、S1313の処理で取得したロードされたオブジェクトファイルの開始アドレスを連結した文字列が書き込まれているメモリ領域の先頭アドレスに、オフジェクト配列の要素番号(0から始まるロード順の番号)から算出されるメモリ領域に書き込まれた文字列の先頭から当該オブジェクトファイルの開始アドレスが記述されている目的の位置までの距離をレジスタBにおいて加算することで、当該オブジェクトファイルの開始アドレスが記述されている目的の位置のアドレスを算出する命令を転送する。   The processing in S1315 is performed by adding the element number of the object array (the number in the loading order starting from 0) to the head address of the memory area in which the character string concatenated with the start address of the loaded object file acquired in the processing in S1313 ), The start address of the object file is described by adding the distance from the head of the character string written in the memory area to the target position where the start address of the object file is described in the register B. The instruction for calculating the address of the target position is transferred.

S1317の処理は、当該オブジェクトファイルの開始アドレスが記述されている目的の位置のアドレスの参照先(当該オブジェクトファイルの開始アドレス)をレジスタBに転送する命令を出力する。   The process of S1317 outputs an instruction to transfer to the register B the reference destination (start address of the object file) of the address at the target position where the start address of the object file is described.

S1319の処理は、レジスタBにリターン元識別ラベルファイルに記述される当該識別ラベル1111に対応するアドレス値1113を加算する命令を出力する。変換後のプログラム実行時において、後述する識別ラベルアドレス取得部160が行う識別ラベルアドレス取得処理(S315)によって、アドレス値1113にはnmコマンドで取得した識別ラベルのアドレスが記述されるが、S1311の処理での判定通り、識別ラベルのアドレス値1113はオフセット値をとる。S1319の処理は、ロードされたオブジェクトファイルの開始アドレスと識別ラベルのアドレス値(オフセット)を加算することで識別ラベルの絶対アドレスを算出する命令を生成している。   In the process of S1319, an instruction to add the address value 1113 corresponding to the identification label 1111 described in the return source identification label file to the register B is output. When the program after the conversion is executed, the address of the identification label acquired by the nm command is described in the address value 1113 by the identification label address acquisition processing (S315) performed by the identification label address acquisition unit 160 described later. As determined in the processing, the address value 1113 of the identification label takes an offset value. The process of S1319 generates an instruction for calculating the absolute address of the identification label by adding the start address of the loaded object file and the address value (offset) of the identification label.

S1311の処理で、識別ラベルが記述されたオブジェクトファイルが位置独立コード化されていないと判定された場合、S1321の処理に移行する。この場合、識別ラベルのアドレスは絶対アドレスとなる。S1321の処理では、アセンブリファイルが自作soソースかどうかを判定する。   If it is determined in step S1311 that the object file in which the identification label is described is not coded in a position independent manner, the process proceeds to step S1321. In this case, the address of the identification label is an absolute address. In the process of S1321, it is determined whether the assembly file is a self-made so source.

当該アセンブリファイルが自作soソースの場合は、実行可能ファイルの中で、自作の共用ライブラリの関数を呼び出す場合に該当する。リターン元識別ラベルファイルに記述される当該識別ラベル1111に対応するアドレス値1113は、実行可能ファイル内に存在するので絶対アドレスとなり、そのままレジスタBに転送する命令を出力(S1323)する。   The case where the assembly file is a self-made so source corresponds to a case where a function of a self-made shared library is called in an executable file. Since the address value 1113 corresponding to the identification label 1111 described in the return source identification label file exists in the executable file, it becomes an absolute address, and outputs an instruction to be transferred to the register B as it is (S1323).

当該アセンブリファイルが自作soソースではない場合は、実行可能ファイルの中で、実行可能ファイル内の関数を呼び出す場合に該当する。実行時に識別ラベルのアドレスを取得してレジスタBに転送する命令を出力(S1325)する。例として、leaq .ATTC_RET_LB_35xqh754_sample_1$1(%rip),%r11となる。本実施例では、例示した関数を利用する。   The case where the assembly file is not a self-made so source corresponds to a case where a function in the executable file is called in the executable file. At the time of execution, an instruction for acquiring the address of the identification label and transferring it to the register B is output (S1325). As an example, leaq. ATTC_RET_LB_35xqh754_sample_1-1 (% rip),% r11. In this embodiment, the exemplified functions are used.

S1327の処理は、レジスタAとBを比較する命令を出力する。S1329の処理は、比較の結果一致していればOKラベルへジャンプする命令を出力する。ジャンプ先のOKラベル先には、レジスタAに格納していたリターンアドレスにジャンプする命令が記述される。以上の処理を当該関数について繰り返す(S1331)。図11に示す関数print_msgでは、関数print_msgの出現回数(4回)各々処理が行われてチェックロジックが出力され呼び出し先アセンブリファイルに記述される。   The process of S1327 outputs an instruction to compare registers A and B. The process of S1329 outputs an instruction to jump to an OK label if the result of the comparison is a match. The instruction to jump to the return address stored in the register A is described in the OK label destination of the jump destination. The above processing is repeated for the function (S1331). In the function print_msg shown in FIG. 11, the number of appearances (four times) of the function print_msg is processed, check logic is output, and described in the callee assembly file.

当該関数に関しての処理が最後まで終わる(S1331)と、NGラベルへジャンプする命令を出力(S1335)する。ジャンプ先のNGラベル先には、プロセスを終了する命令が記述される。以上が、命令生成挿入処理ブロックB20の処理である。   When the processing for the function is completed to the end (S1331), an instruction to jump to the NG label is output (S1335). At the NG label destination of the jump destination, an instruction to end the process is described. The above is the processing of the instruction generation / insertion processing block B20.

図3に戻って、チェック処理ブロックB30の処理について説明する。チェック処理ブロックB30は、識別ラベルのアドレスを取得し、取得したアドレスを識別ラベルと紐づけて識別ラベルアドレスとして保持する識別ラベルアドレス取得処理(S315)と、変換対象プログラムが正常起動するかを判定し、正常に起動した場合にはプログラムの変換を終了し、正常に起動しない場合には、識別ラベルアドレスの再取得を命令し、リターンアドレスチェック命令の更新を命令し、再度正常起動するかを判定する処理を行なうリターンアドレスチェック命令更新処理(S317)からなる。     Returning to FIG. 3, the processing of the check processing block B30 will be described. The check processing block B30 acquires the address of the identification label, associates the acquired address with the identification label, and holds the acquired address as the identification label address (S315), and determines whether the conversion target program starts normally. If it starts normally, it ends the program conversion.If it does not start normally, it instructs re-acquisition of the identification label address, instructs the update of the return address check instruction, and restarts normally. It consists of a return address check instruction update process (S317) for performing the determination process.

チェック処理ブロックB30に処理が移行すると、まず1回、実行可能ファイルと共用ライブラリを作成する。チェック処理ブロックB30は、命令生成挿入処理ブロックB20の処理で書き換えられたプログラムが正常に起動することを確認するためである。   When the processing shifts to the check processing block B30, first, an executable file and a shared library are created once. The check processing block B30 is for confirming that the program rewritten in the processing of the instruction generation / insertion processing block B20 starts normally.

図14は、識別ラベルアドレス取得処理(S315)を示すフローチャートである。識別ラベルアドレス取得部160が識別ラベルアドレス取得処理(S315)を実行する。関係情報生成部100が生成した関係情報(図4参照)に基づいて、すべてのソースファイルディレクトリ41について(S1401)、対応するオブジェクトファイル40を取得(S1403)する。各々のオブジェクトファイルからnmコマンドによってシンボル名とシンボルに対する実行可能ファイル作成後のアドレスを取得(S1405)する。シンボル名が合致するものについてリターン元識別ファイルのアドレス値1113を書き換える(S1409)。この一連の処理により、リターン元識別ファイルのアドレス値1113が実行時のアドレス値になり、識別ラベルと紐づけられる。   FIG. 14 is a flowchart showing the identification label address acquisition processing (S315). The identification label address acquisition unit 160 executes an identification label address acquisition process (S315). Based on the relationship information (see FIG. 4) generated by the relationship information generation unit 100, the corresponding object files 40 are obtained for all the source file directories 41 (S1401) (S1403). The symbol name and the address after the executable file is created for the symbol are acquired from each object file by the nm command (S1405). The address value 1113 of the return source identification file is rewritten for a symbol whose name matches that of the symbol name (S1409). Through this series of processing, the address value 1113 of the return source identification file becomes the address value at the time of execution, and is associated with the identification label.

図15は、リターンアドレスチェック命令更新処理(S317)を示すフローチャートである。リターンアドレスチェック命令更新処理部170がリターンアドレスチェック命令更新処理(S317)を実行する。識別ラベルアドレス取得処理(S315)によって取得したアドレス値に書き換えたリターン元識別ファイルのアドレス値1113を反映するために、リターンアドレスチェック命令生成(図13)を再度実行することで、リターン元識別ファイルのアドレス値1113として実行時のアドレス値を埋め込まれたリターンアドレスチェック命令を生成する。また、リターンアドレスチェック命令生成挿入処理(S313)によって、アセンブリファイルにリターンアドレスチェック命令を挿入するとファイルサイズが当初より大きくなるため、挿入した識別ラベルのアドレス値が変化する。こうなると、リターンアドレスが当初の想定と異なる値を取り、リターンアドレスが改ざんされたと判断され、プロセスが異常終了してしまう。そこで、このような状況に対応するため、実行可能ファイル及び共用ライブラリを作成して正常動作するかを確認し、正常に起動した場合にはプログラムの変換を終了し、正常に起動しない場合には、識別ラベルアドレスの再取得を命令し、リターンアドレスチェック命令の更新を命令し、再度正常起動するかを判定する処理を行なう。   FIG. 15 is a flowchart showing the return address check instruction update processing (S317). The return address check instruction update processing section 170 executes the return address check instruction update processing (S317). By executing the return address check command generation (FIG. 13) again to reflect the rewritten address value 1113 of the return source identification file to the address value acquired in the identification label address acquisition process (S315), the return source identification file A return address check instruction in which the address value at the time of execution is embedded as the address value 1113 of the instruction is generated. Also, when the return address check instruction is inserted into the assembly file by the return address check instruction generation / insertion processing (S313), the file size becomes larger than the initial size, so that the address value of the inserted identification label changes. In this case, the return address takes a value different from the originally assumed value, it is determined that the return address has been falsified, and the process ends abnormally. Therefore, in order to cope with such a situation, create an executable file and a shared library and check whether it operates normally.If it starts normally, terminate the program conversion.If it does not start normally, , An instruction to re-acquire the identification label address, an instruction to update the return address check instruction, and a process to determine whether or not to normally start again.

図15に沿って、リターンアドレスチェック命令更新処理(S317)を説明する。関係情報生成部100が生成した関係情報(図4参照)に基づいて、すべてのソースファイルディレクトリ41について(S1501)、関係づけられた構成オブジェクトファイル42に対応(S1503)するアセンブリファイル名を引数として、引数としたアセンブリファイルに記述されたリターンアドレスチェックロジックを更新(S1505)する。その後、実行可能ファイル及び共用ライブラリを作成(S1507)して、実行可能ファイルを起動(S1509)する。正常起動したか判定(S1511)を行い、正常起動すればリターンする。正常起動しない場合は、再度、識別ラベルアドレス取得処理(S315)に戻って実行を続ける。   The return address check instruction update processing (S317) will be described with reference to FIG. Based on the relation information generated by the relation information generation unit 100 (see FIG. 4), the assembly file names corresponding to the related configuration object files 42 (S1503) are used as arguments for all the source file directories 41 (S1501). Then, the return address check logic described in the assembly file as the argument is updated (S1505). Thereafter, an executable file and a shared library are created (S1507), and the executable file is activated (S1509). A determination is made as to whether or not normal startup has been performed (S1511). If it does not start normally, the process returns to the identification label address acquisition process (S315) and continues the execution.

図16は、リターンアドレスチェックロジック更新(S1505)についての詳細を示すフローチャートである。図16に沿って、リターンアドレスチェックロジック更新(S1505)について説明する。S1601の処理では、引数で指定されたアセンブリファイルを開き、先頭行から終端まで順次書き換えを行う。S1603の処理では、チェックロジックが記述されている部分かどうかの判定を行う。チェックロジックの記述部分でない場合には、そのまま行を出力(S1605)して次の行に移行(S1613)する。チェックロジックの記述部分である場合には、関数ごとに記述してあるリターンアドレスチェックラベルかどうかを判定(S1607)する。リターンアドレスチェックラベルでない場合には、次の行に移行(S1613)する。リターンアドレスチェックラベルである場合には、ラベルから関数名を取得(S1609)して取得した関数名を引数としてリターンアドレスチェック命令生成(図13)を実行(S1611)する。   FIG. 16 is a flowchart showing details of the return address check logic update (S1505). The update of the return address check logic (S1505) will be described with reference to FIG. In the process of S1601, the assembly file specified by the argument is opened, and rewriting is performed sequentially from the first line to the end. In the process of S1603, it is determined whether or not the part describes the check logic. If it is not the description part of the check logic, the line is output as it is (S1605) and the process proceeds to the next line (S1613). If it is the description part of the check logic, it is determined whether or not it is a return address check label described for each function (S1607). If the label is not a return address check label, the process moves to the next line (S1613). If the label is a return address check label, a function name is obtained from the label (S1609), and a return address check instruction is generated (FIG. 13) using the obtained function name as an argument (S1611).

以上が、チェック処理ブロックB30の処理である。チェック処理ブロックB30の処理が終了すると、図3に戻って引数で指定された次の変換対象プログラムの変換処理に移行(S301)する。すべての変換対象プログラムについて変換処理が完了すると、変換装置10による変換対象プログラムの変換が完了する。   The above is the processing of the check processing block B30. When the processing of the check processing block B30 is completed, returning to FIG. 3, the processing shifts to the conversion processing of the next conversion target program specified by the argument (S301). When the conversion process is completed for all the conversion target programs, the conversion of the conversion target program by the conversion device 10 is completed.

(第2実施形態)
本実施形態に係る変換装置は、第1実施形態の変換装置の機能に加えて、標準関数については識別ラベルのアドレスを実行時に取得してレジスタに格納するようにプログラムを変換する変換装置である。
(2nd Embodiment)
The conversion device according to the present embodiment is a conversion device that converts a program so that, in addition to the functions of the conversion device according to the first embodiment, the address of the identification label is acquired at the time of execution for a standard function and stored in a register. .

呼び出される関数が標準関数の場合、標準関数はバイナリで提供されるので、直接ソースファイルにリターンアドレスチェック命令を記述することができない。一方、標準関数は位置独立コード化されていないため、アドレスを取得した場合、絶対アドレスとなる。第2実施形態の変換装置は、標準関数については、識別ラベルのアドレスを実行時に取得してレジスタに格納するように変換対象プログラムを変換する。第1実施形態と比較すると、公開されているソースコードに基づいて同じ動作をする自作した標準関数を新たな共有ライブラリとして配置する必要がないので汎用的である一方、以降に説明するように、レジスタは関数呼び出しなどによってスタックに退避、復元を繰り返すため、第1実施形態に比べ改ざんリスクは高くなる。   If the function to be called is a standard function, the standard function is provided in binary, so the return address check instruction cannot be described directly in the source file. On the other hand, since the standard function is not coded in a position-independent manner, when the address is obtained, it becomes an absolute address. The conversion device of the second embodiment converts the conversion target program so that the address of the identification label is acquired at the time of execution and stored in the register for the standard function. Compared to the first embodiment, it is versatile because it is not necessary to arrange a self-made standard function that performs the same operation based on the published source code as a new shared library, while as described below, Since the register is repeatedly saved and restored on the stack by a function call or the like, the risk of tampering is higher than in the first embodiment.

第2実施形態では、識別ラベル生成挿入処理(S309)とリターンアドレスチェック命令生成挿入処理(S313)が第1実施形態と異なる。いずれも、呼び出される関数が標準関数の場合の処理が追加される。第2実施形態で追加される処理を中心に説明する。   In the second embodiment, the identification label generation and insertion processing (S309) and the return address check instruction generation and insertion processing (S313) are different from the first embodiment. In each case, processing when the function to be called is a standard function is added. The following description focuses on the processing added in the second embodiment.

図17は、第2実施形態での識別ラベル生成挿入処理を示すフローチャートである。第1実施形態での識別ラベル生成挿入処理(図10)と異なり、call命令を検出(S1003)した後、呼び出される関数が標準関数かどうかの判定(S1713)を行う。標準関数でない場合には第1実施形態と同様の処理となる。標準関数の場合、標準ライブラリ関数識別ラベル出力(S1715)に移行する。S1717の処理は、アセンブリファイル別に使用される標準関数のリストを生成する。同じ標準関数(例えば、printf)であっても記述されているアセンブリファイルが異なると標準関数の処理終了後のリターン元のアドレスが異なるからである。   FIG. 17 is a flowchart illustrating an identification label generation and insertion process according to the second embodiment. Unlike the identification label generation and insertion processing (FIG. 10) in the first embodiment, after detecting the call instruction (S1003), it is determined whether the called function is a standard function (S1713). If it is not a standard function, the same processing as in the first embodiment is performed. In the case of the standard function, the flow shifts to standard library function identification label output (S1715). The processing in S1717 generates a list of standard functions used for each assembly file. This is because, even if the same standard function (for example, printf) is written in a different assembly file, the address of the return source after processing of the standard function is different.

図18は、標準ライブラリ関数識別ラベル出力(S1715)について示すフローチャートである。標準関数を呼び出すcall命令を書き換える。call命令が呼び出した標準関数の処理が終了した後にリターンすべき場所を特定するための識別ラベルのアドレスを実行時に取得してレジスタに格納する命令(S1805)と、標準関数の呼び出し用ラベルを生成して、そのラベルにジャンプする命令(S1807)を出力する。ジャンプ命令の次にcall命令が呼び出した標準関数の処理が終了した後にリターンすべき場所を特定するための識別ラベルを出力(S1809)する。   FIG. 18 is a flowchart showing the standard library function identification label output (S1715). Rewrite the call instruction that calls the standard function. An instruction (S1805) for acquiring an address of an identification label for specifying a place to return to after execution of the standard function called by the call instruction and storing the address in a register, and generating a label for calling the standard function Then, an instruction to jump to the label (S1807) is output. After the processing of the standard function called by the call instruction following the jump instruction, an identification label for specifying a place to return to is output (S1809).

図19は、第2実施形態でのリターンアドレスチェック命令生成挿入処理を(S313)示すフローチャートである。第1実施形態での処理フロー(図12)に、標準関数コール部生成出力処理(S1909)が追加される。   FIG. 19 is a flowchart showing (S313) the return address check instruction generation and insertion processing in the second embodiment. A standard function call part generation and output process (S1909) is added to the process flow (FIG. 12) in the first embodiment.

図20は、標準関数コール処理生成出力処理(S1909)を示すフローチャートである。標準関数コール処理は、S1807の処理で生成された標準関数の呼び出し用ラベルにジャンプした際の標準関数実行と標準関数の処理が終了した後に予めレジスタに格納していた適正なアドレスへリターンする処理である。   FIG. 20 is a flowchart showing the standard function call process generation and output process (S1909). The standard function call process is a process of executing the standard function when jumping to the label for calling the standard function generated in the process of S1807 and returning to an appropriate address previously stored in the register after the process of the standard function is completed. It is.

S2003の処理では、S1717の処理で生成されたアセンブリファイル別標準関数のリストの要素である標準関数について順次標準関数コール処理を生成する。S2005の処理では、S1807の処理で生成された標準関数の呼び出し用ラベルを出力する。S2007の処理では、当該関数をコールする命令を出力する。S2009の処理では、標準関数コール共通処理にジャンプする命令を出力する。図20に示すように、ジャンプ先の標準関数コール共通処理では、S1805の処理で実行時に取得してレジスタに格納したリターンすべき場所を特定するための識別ラベルのアドレスにジャンプする。   In the processing of S2003, standard function call processing is sequentially generated for standard functions that are elements of the list of standard functions for each assembly file generated in the processing of S1717. In the process of S2005, the label for calling the standard function generated in the process of S1807 is output. In the process of S2007, an instruction to call the function is output. In the process of S2009, an instruction to jump to the standard function call common process is output. As shown in FIG. 20, in the standard function call common process at the jump destination, the process jumps to the address of the identification label for specifying the place to return, which is obtained at the time of execution in the process of S1805 and stored in the register.

(第3実施形態)
本実施形態は、コンピュータシステムを変換装置10として機能させるための変換プログラムである。コンピュータシステムの構成は、図2に示す通りである。
(Third embodiment)
The present embodiment is a conversion program for causing a computer system to function as the conversion device 10. The configuration of the computer system is as shown in FIG.

変換プログラムは、メインモジュール、入力モジュール、出力モジュール及び演算処理モジュールを備える。メインモジュールは変換処理を統括的に制御する部分である。入力モジュールは変換対象のプログラムの入力を、出力モジュールは変換後のプログラムの出力をするようにコンピュータシステムを動作させる。演算処理モジュールは、関係情報生成モジュール、ロードアドレス算出命令挿入モジュール、コンパイラ、識別ラベル生成挿入モジュール、リターン命令書き換えモジュール、識別ラベルアドレス取得モジュール、リターンアドレスチェック命令生成挿入モジュール及びリターンアドレスチェック命令更新モジュールを備える。メインモジュール、入力モジュール、出力モジュール及び演算処理モジュールを実行させることにより実現される機能は、変換装置10の関係情報生成部100、ロードアドレス算出命令挿入部110、コンパイラ120、識別ラベル生成挿入部130、リターン命令書き換え部140、リターンアドレスチェック命令生成挿入部150、識別ラベルアドレス取得部160及びリターンアドレスチェック命令更新部170の機能とそれぞれ同様である。   The conversion program includes a main module, an input module, an output module, and an arithmetic processing module. The main module is a part that comprehensively controls the conversion process. The input module operates the computer system to input a program to be converted and the output module to output the converted program. The arithmetic processing module includes a relation information generation module, a load address calculation instruction insertion module, a compiler, an identification label generation and insertion module, a return instruction rewriting module, an identification label address acquisition module, a return address check instruction generation and insertion module, and a return address check instruction update module. Is provided. The functions realized by executing the main module, the input module, the output module, and the arithmetic processing module include a relation information generation unit 100, a load address calculation instruction insertion unit 110, a compiler 120, and an identification label generation and insertion unit 130 of the conversion device 10. , Return instruction rewriting unit 140, return address check instruction generation and insertion unit 150, identification label address acquisition unit 160, and return address check instruction update unit 170, respectively.

10 変換装置
100 関係情報生成部
110 ロードアドレス算出命令挿入部
120 コンパイラ
130 識別ラベル生成挿入部
140 リターン命令書き換え部
150 リターンアドレスチェック命令生成挿入部
160 識別ラベルアドレス取得部
170 リターンアドレスチェック命令更新部
20 ハードウェア構成
210 中央演算装置(CPU)
220 入力装置
230 出力装置
240 主記憶装置(RAM/ROM)
250 補助記憶装置
260 複数のレジスタ
B10 情報取得処理ブロック
B20 命令生成挿入処理ブロック
B30 チェック処理ブロック
REFERENCE SIGNS LIST 10 conversion device 100 relational information generation unit 110 load address calculation instruction insertion unit 120 compiler 130 identification label generation and insertion unit 140 return instruction rewriting unit 150 return address check instruction generation and insertion unit 160 identification label address acquisition unit 170 return address check instruction update unit 20 Hardware configuration 210 Central processing unit (CPU)
220 input device 230 output device 240 main storage device (RAM / ROM)
250 Auxiliary storage device 260 Multiple registers B10 Information acquisition processing block B20 Instruction generation and insertion processing block B30 Check processing block

Claims (5)

リターンアドレスの改ざんを検知して停止するようにプログラムを変換する変換装置であって、
変換対象プログラムを構成する実行可能なオブジェクトファイルについて、ソースファイルの存在するディレクトリと、ソースファイルを構成するオブジェクトファイルと、シンボル名と、が互いに紐づく関係を示す関係情報をメモリマップに基づいて生成する、関係情報生成部と、
前記変換対象プログラムの開始アドレス及び前記変換対象プログラムにリンクされる共有ライブラリの開始アドレスをメモリマップに基づいて算出し、保持する命令を、前記変換対象プログラムの実行開始直後に、前記変換対象プログラムから、この命令を呼び出すことができるように前記変換対象プログラムに挿入する、開始アドレス算出命令挿入部と、
前記変換対象プログラムに含まれる関数呼び出し命令を検出し、前記関数呼び出し命令が呼び出した関数の処理が終了した後にリターンすべき場所を特定するための識別ラベルを生成し、検出した前記関数呼び出し命令と次の命令との間に前記識別ラベルを挿入する、識別ラベル生成挿入部と、
前記変換対象プログラムに含まれるリターン命令を検出し、検出した前記リターン命令を、前記変換対象プログラム実行時に前記リターン命令がリターン先として指し示すアドレスが識別ラベルのアドレスから算出したリターンすべき絶対アドレスと一致しているかを判定して一致しない場合には前記変換対象プログラムを終了させるリターンアドレスチェック命令へ分岐する命令、に書き換える、リターン命令書き換え部と、
前記変換対象プログラムに、前記リターンアドレスチェック命令を生成し、挿入する、リターンアドレスチェック命令生成挿入部と、
前記識別ラベルのアドレスを取得し、取得したアドレスを識別ラベルと紐づけて前記識別ラベルアドレスとして保持する、識別ラベルアドレス取得部と、
前記変換対象プログラムが正常起動するかを判定し、正常に起動した場合にはプログラムの変換を終了し、正常に起動しない場合には、前記識別ラベルアドレス取得部に前記識別ラベルアドレスの再取得を命令し、前記リターンアドレスチェック命令生成挿入部に前記リターンアドレスチェック命令の更新を命令し、再度正常起動するかを判定する処理を行なう、リターンアドレスチェック命令更新部と、
を備えることを特徴とする変換装置
A conversion device that converts a program so as to stop when the return address is tampered with,
Based on the memory map, for the executable object files that make up the conversion target program, the relationship information that indicates the relationship between the directory where the source files exist, the object files that make up the source files, and the symbol names is generated based on the memory map A relational information generator,
The start address of the conversion target program and the start address of the shared library linked to the conversion target program are calculated based on the memory map, and an instruction to be held is obtained from the conversion target program immediately after the execution of the conversion target program is started. A start address calculation instruction insertion unit to be inserted into the conversion target program so that the instruction can be called;
The function call instruction included in the conversion target program is detected, and an identification label for specifying a place to return after the processing of the function called by the function call instruction is completed is generated. Inserting the identification label between the next instruction, an identification label generation insertion unit,
A return instruction included in the conversion target program is detected, and the detected return instruction is matched with the absolute address to be returned calculated from the address of the identification label when the address indicated by the return instruction as the return destination when the conversion target program is executed. A return instruction rewriting unit for rewriting to an instruction for branching to a return address check instruction for terminating the program to be converted when it is determined that they do not match,
A return address check instruction generation and insertion unit that generates and inserts the return address check instruction in the conversion target program;
Acquiring the address of the identification label, holding the acquired address as the identification label address in association with the identification label, an identification label address acquisition unit,
It is determined whether the conversion target program starts normally.If the program starts normally, the program conversion is terminated.If the program does not start normally, the identification label address acquisition unit reacquires the identification label address. A return address check instruction update unit, which instructs the return address check instruction generation / insertion unit to update the return address check instruction, and performs a process of determining whether to normally start again.
Conversion device characterized by comprising:
前記リターンアドレスチェック命令生成挿入部が生成する前記リターンアドレスチェック命令は、変換対象プログラム実行時に、関数呼び出し命令が呼び出した関数の処理が終了した後にリターンすべき場所を特定するための識別ラベルが記述されたファイルが位置独立コード化されている場合には前記識別ラベルが記述されたファイルの開始アドレスに前記識別ラベルのオフセット値を取得して加算することで、位置独立コード化されていない場合には識別ラベルのアドレスを取得することで、リターンすべきアドレスを算出する、
ことを特徴とする請求項1に記載の変換装置
The return address check instruction generated by the return address check instruction generation / insertion section describes an identification label for specifying a place to return to after the processing of the function called by the function call instruction is completed when the conversion target program is executed. If the obtained file is position-independent coded, by obtaining and adding the offset value of the identification label to the start address of the file in which the identification label is described, if the position-independent coding is not performed, Calculates the address to return by obtaining the address of the identification label,
The conversion device according to claim 1, wherein:
前記識別ラベル生成挿入部は、検出した関数呼び出し命令が呼び出す関数が標準関数である場合には、前記標準関数を呼び出す命令を、前記標準関数の処理が終了した後にリターンすべき場所を特定するための識別ラベルの実行時のアドレスを取得してレジスタに格納する命令及び前記標準関数に分岐する命令に書き換え、前記標準関数に分岐する命令と次の命令との間に前記識別ラベルを挿入する処理を、
前記リターンアドレスチェック命令生成挿入部は、前記標準関数の処理が終了した後に前記識別ラベル生成挿入部がレジスタに格納したアドレスへリターンする命令を生成し、変換対象プログラムに挿入する処理を、
更に備えることを特徴とする請求項1又は請求項2に記載の変換装置
When the function called by the detected function call instruction is a standard function, the identification label generation / insertion unit specifies the instruction to call the standard function by specifying a place to return after the processing of the standard function is completed. Processing for obtaining the address of the identification label at the time of execution and storing it in a register and an instruction branching to the standard function, and inserting the identification label between the instruction branching to the standard function and the next instruction To
The return address check instruction generation and insertion unit generates an instruction to return to the address stored in the register by the identification label generation and insertion unit after the processing of the standard function is completed, and inserts the instruction into the conversion target program.
The conversion device according to claim 1 or 2, further comprising:
コンピュータに、
リターンアドレスの改ざんを検知して停止するようにプログラムの変換を実行させる変換プログラムであって、
変換対象プログラムを構成する実行可能なオブジェクトファイルについて、ソースファイルの存在するディレクトリと、ソースファイルを構成するオブジェクトファイルと、シンボル名と、が互いに紐づく関係を示す関係情報をメモリマップに基づいて生成する、関係情報生成処理ステップと、
前記変換対象プログラムの開始アドレス及び前記変換対象プログラムにリンクされる共有ライブラリの開始アドレスをメモリマップに基づいて算出し、保持する命令を、前記変換対象プログラムの実行開始直後に、前記変換対象プログラムから、この命令を呼び出すことができるように前記変換対象プログラムに挿入する、開始アドレス算出命令挿入処理ステップと、
前記変換対象プログラムに含まれる関数呼び出し命令を検出し、前記関数呼び出し命令が呼び出した関数の処理が終了した後にリターンすべき場所を特定するための識別ラベルを生成し、検出した前記関数呼び出し命令と次の命令との間に前記識別ラベルを挿入する、識別ラベル生成挿入処理ステップと、
前記変換対象プログラムに含まれるリターン命令を検出し、検出した前記リターン命令を、前記変換対象プログラム実行時に前記リターン命令がリターン先として指し示すアドレスが識別ラベルのアドレスから算出したリターンすべき絶対アドレスと一致しているかを判定して一致しない場合には前記変換対象プログラムを終了させるリターンアドレスチェック命令へ分岐する命令、に書き換える、リターン命令書き換え処理ステップと、
前記変換対象プログラムに、前記リターンアドレスチェック命令を生成し、挿入する、リターンアドレスチェック命令生成挿入処理ステップと、
前記識別ラベルのアドレスを取得し、取得したアドレスを識別ラベルと紐づけて前記識別ラベルアドレスとして保持する、識別ラベルアドレス取得処理ステップと、
前記変換対象プログラムが正常起動するかを判定し、正常に起動した場合にはプログラムの変換を終了し、正常に起動しない場合には、前記識別ラベルアドレス取得部に前記識別ラベルアドレスの再取得を命令し、前記リターンアドレスチェック命令生成挿入部に前記リターンアドレスチェック命令の更新を命令し、再度正常起動するかを判定する処理を行なう、リターンアドレスチェック命令更新処理ステップと、
を実行させる変換プログラム
On the computer,
A conversion program for executing a program conversion so as to detect and stop return address tampering,
Based on the memory map, for the executable object files that make up the conversion target program, the relationship information that indicates the relationship between the directory where the source files exist, the object files that make up the source files, and the symbol names is generated based on the memory map A relation information generation processing step;
The start address of the conversion target program and the start address of the shared library linked to the conversion target program are calculated based on the memory map, and an instruction to be held is obtained from the conversion target program immediately after the execution of the conversion target program is started. Inserting a start address calculation instruction into the conversion target program so that the instruction can be called;
The function call instruction included in the conversion target program is detected, and an identification label for specifying a place to return after the processing of the function called by the function call instruction is completed is generated. Inserting the identification label between the next instruction, identification label generation insertion processing step,
A return instruction included in the conversion target program is detected, and the detected return instruction is matched with the absolute address to be returned calculated from the address of the identification label when the address indicated by the return instruction as the return destination when the conversion target program is executed. A return instruction rewriting processing step of rewriting the instruction to branch to a return address check instruction for terminating the program to be converted when it is determined that they do not match,
A return address check instruction generation / insertion processing step of generating and inserting the return address check instruction in the conversion target program;
Acquiring the address of the identification label, holding the acquired address as the identification label address in association with the identification label, an identification label address acquisition processing step,
It is determined whether the conversion target program starts normally.If the program starts normally, the program conversion is terminated.If the program does not start normally, the identification label address acquisition unit reacquires the identification label address. A return address check instruction update processing step of instructing the return address check instruction generation / insertion unit to update the return address check instruction, and performing a process of determining whether to normally start again.
Conversion program to execute
リターンアドレスの改ざんを検知して停止するようにプログラムを変換するプログラム変換方法であって、
リターンアドレスの改ざんを検知して停止するようにプログラムの変換を実行させる変換プログラムであって、
変換対象プログラムを構成する実行可能なオブジェクトファイルについて、ソースファイルの存在するディレクトリと、ソースファイルを構成するオブジェクトファイルと、シンボル名と、が互いに紐づく関係を示す関係情報をメモリマップに基づいて生成する、関係情報生成処理ステップと、
前記変換対象プログラムの開始アドレス及び前記変換対象プログラムにリンクされる共有ライブラリの開始アドレスをメモリマップに基づいて算出し、保持する命令を、前記変換対象プログラムの実行開始直後に、前記変換対象プログラムから、この命令を呼び出すことができるように前記変換対象プログラムに挿入する、開始アドレス算出命令挿入処理ステップと、
前記変換対象プログラムに含まれる関数呼び出し命令を検出し、前記関数呼び出し命令が呼び出した関数の処理が終了した後にリターンすべき場所を特定するための識別ラベルを生成し、検出した前記関数呼び出し命令と次の命令との間に前記識別ラベルを挿入する、識別ラベル生成挿入処理ステップと、
前記変換対象プログラムに含まれるリターン命令を検出し、検出した前記リターン命令を、前記変換対象プログラム実行時に前記リターン命令がリターン先として指し示すアドレスが識別ラベルのアドレスから算出したリターンすべき絶対アドレスと一致しているかを判定して一致しない場合には前記変換対象プログラムを終了させるリターンアドレスチェック命令へ分岐する命令、に書き換える、リターン命令書き換え処理ステップと、
前記変換対象プログラムに、前記リターンアドレスチェック命令を生成し、挿入する、リターンアドレスチェック命令生成挿入処理ステップと、
前記識別ラベルのアドレスを取得し、取得したアドレスを識別ラベルと紐づけて前記識別ラベルアドレスとして保持する、識別ラベルアドレス取得処理ステップと、
前記変換対象プログラムが正常起動するかを判定し、正常に起動した場合にはプログラムの変換を終了し、正常に起動しない場合には、前記識別ラベルアドレス取得部に前記識別ラベルアドレスの再取得を命令し、前記リターンアドレスチェック命令生成挿入部に前記リターンアドレスチェック命令の更新を命令し、再度正常起動するかを判定する処理を行なう、リターンアドレスチェック命令更新処理ステップと、
をコンピュータが実行するプログラム変換方法
A program conversion method for converting a program to detect return address tampering and stop,
A conversion program for executing a program conversion so as to detect and stop return address tampering,
Based on the memory map, for the executable object files that make up the conversion target program, the relationship information that indicates the relationship between the directory where the source files exist, the object files that make up the source files, and the symbol names is generated based on the memory map A relation information generation processing step;
The start address of the conversion target program and the start address of the shared library linked to the conversion target program are calculated based on the memory map, and an instruction to be held is obtained from the conversion target program immediately after the execution of the conversion target program is started. Inserting a start address calculation instruction into the conversion target program so that the instruction can be called;
A function call instruction included in the conversion target program is detected, and an identification label for specifying a place to return to after the processing of the function called by the function call instruction is completed is generated. Inserting the identification label between the next instruction, identification label generation insertion processing step,
A return instruction included in the conversion target program is detected, and the detected return instruction is matched with the absolute address to be returned calculated from the address of the identification label when the address indicated as the return destination by the return instruction when executing the conversion target program. A return instruction rewriting processing step of rewriting the instruction to branch to a return address check instruction for terminating the program to be converted if it is determined that the two do not match, and
A return address check instruction generation and insertion processing step of generating and inserting the return address check instruction in the conversion target program;
Acquiring the address of the identification label, holding the acquired address as the identification label address in association with the identification label, an identification label address acquisition processing step,
It is determined whether the conversion target program starts normally.If the program starts normally, the conversion of the program ends.If the program does not start normally, the identification label address acquisition unit reacquires the identification label address. A return address check instruction update processing step of instructing the return address check instruction generation / insertion unit to update the return address check instruction, and performing a process of determining whether to normally start again.
Conversion method of computer-executed program
JP2018152795A 2018-08-15 2018-08-15 Conversion device, conversion program, and program conversion method Active JP6460433B1 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP2018152795A JP6460433B1 (en) 2018-08-15 2018-08-15 Conversion device, conversion program, and program conversion method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP2018152795A JP6460433B1 (en) 2018-08-15 2018-08-15 Conversion device, conversion program, and program conversion method

Publications (2)

Publication Number Publication Date
JP6460433B1 JP6460433B1 (en) 2019-01-30
JP2020027512A true JP2020027512A (en) 2020-02-20

Family

ID=65228921

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2018152795A Active JP6460433B1 (en) 2018-08-15 2018-08-15 Conversion device, conversion program, and program conversion method

Country Status (1)

Country Link
JP (1) JP6460433B1 (en)

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2011008778A (en) * 2009-05-27 2011-01-13 Ntt Docomo Inc Method and device for preventing modification of program execution flow
US20110289586A1 (en) * 2004-07-15 2011-11-24 Kc Gaurav S Methods, systems, and media for detecting and preventing malcode execution
US20150356294A1 (en) * 2014-06-09 2015-12-10 Lehigh University Methods for enforcing control flow of a computer program
JP2016115033A (en) * 2014-12-12 2016-06-23 富士通株式会社 Instruction execution controller and instruction execution control method
US20180089422A1 (en) * 2016-09-27 2018-03-29 Intel Corporation Technologies for deterministic code flow integrity protection
JP6338796B1 (en) * 2018-01-09 2018-06-06 株式会社Attc Conversion device, conversion program, and program conversion method

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20110289586A1 (en) * 2004-07-15 2011-11-24 Kc Gaurav S Methods, systems, and media for detecting and preventing malcode execution
JP2011008778A (en) * 2009-05-27 2011-01-13 Ntt Docomo Inc Method and device for preventing modification of program execution flow
US20150356294A1 (en) * 2014-06-09 2015-12-10 Lehigh University Methods for enforcing control flow of a computer program
JP2016115033A (en) * 2014-12-12 2016-06-23 富士通株式会社 Instruction execution controller and instruction execution control method
US20180089422A1 (en) * 2016-09-27 2018-03-29 Intel Corporation Technologies for deterministic code flow integrity protection
JP6338796B1 (en) * 2018-01-09 2018-06-06 株式会社Attc Conversion device, conversion program, and program conversion method

Also Published As

Publication number Publication date
JP6460433B1 (en) 2019-01-30

Similar Documents

Publication Publication Date Title
JP6856749B2 (en) Systems and methods for implementing native contracts on the blockchain
JP6338796B1 (en) Conversion device, conversion program, and program conversion method
CN111033468B (en) System and method for implementing different types of blockchain contracts
EP2434394B1 (en) Method, device and system for activating on-line patch
US7055035B2 (en) Method for generating a read only memory image
US9411964B1 (en) Characterizing, detecting and healing vulnerabilities in computer code
US8914780B2 (en) Incremental generation of managed assemblies
CN103093150B (en) A kind of dynamic integrity protection method based on credible chip
JP2008502968A (en) Method for loading software comprising an intermediate object-oriented language onto a portable device
CN111095198A (en) System and method for data processing
KR20190061075A (en) Method and apparatus for preventing software repackaging
US20220198003A1 (en) Detecting added functionality in open source package
US20220107827A1 (en) Applying security mitigation measures for stack corruption exploitation in intermediate code files
CN103345412A (en) Patching method and device
US20100269105A1 (en) Method of determining which computer program functions are changed by an arbitrary source code modification
CN111190584B (en) EHIS-DB system version release method, EHIS-DB system version release device, computer equipment and storage medium
US8196093B2 (en) Apparatus and method for componentizing legacy system
US20190205528A1 (en) Automated software application verification system
JP6460433B1 (en) Conversion device, conversion program, and program conversion method
JP6468098B2 (en) Information processing program, apparatus, and method
WO2020240830A1 (en) Detection device, detection method, and detection program
JP6579095B2 (en) Program writing method, apparatus control method, program writing program, and apparatus control program
US10310871B2 (en) Non-transitory computer-readable recording medium storing control program, control device and control method
KR20200017120A (en) Method and system for protecting code using code spraying
CN113220303A (en) Compiling method and system of kernel module

Legal Events

Date Code Title Description
A621 Written request for application examination

Free format text: JAPANESE INTERMEDIATE CODE: A621

Effective date: 20180821

A871 Explanation of circumstances concerning accelerated examination

Free format text: JAPANESE INTERMEDIATE CODE: A871

Effective date: 20180821

A975 Report on accelerated examination

Free format text: JAPANESE INTERMEDIATE CODE: A971005

Effective date: 20181030

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20181105

A521 Request for written amendment filed

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20181121

TRDD Decision of grant or rejection written
A01 Written decision to grant a patent or to grant a registration (utility model)

Free format text: JAPANESE INTERMEDIATE CODE: A01

Effective date: 20181203

A61 First payment of annual fees (during grant procedure)

Free format text: JAPANESE INTERMEDIATE CODE: A61

Effective date: 20181219

R150 Certificate of patent or registration of utility model

Ref document number: 6460433

Country of ref document: JP

Free format text: JAPANESE INTERMEDIATE CODE: R150

R250 Receipt of annual fees

Free format text: JAPANESE INTERMEDIATE CODE: R250

R250 Receipt of annual fees

Free format text: JAPANESE INTERMEDIATE CODE: R250