JP6460433B1 - Conversion device, conversion program, and program conversion method - Google Patents

Conversion device, conversion program, and program conversion method Download PDF

Info

Publication number
JP6460433B1
JP6460433B1 JP2018152795A JP2018152795A JP6460433B1 JP 6460433 B1 JP6460433 B1 JP 6460433B1 JP 2018152795 A JP2018152795 A JP 2018152795A JP 2018152795 A JP2018152795 A JP 2018152795A JP 6460433 B1 JP6460433 B1 JP 6460433B1
Authority
JP
Japan
Prior art keywords
instruction
address
return
identification label
target 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.)
Active
Application number
JP2018152795A
Other languages
Japanese (ja)
Other versions
JP2020027512A (en
Inventor
平 昌展
昌展 平
Original Assignee
株式会社Attc
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 filed Critical 株式会社Attc
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

Abstract

【課題】ソフトウェアの脆弱性を利用した攻撃によるリターンアドレスの改ざんを検知して不正なプログラムの実行を防止すること。
【解決手段】本発明は、変換対象プログラムに含まれる関数呼び出し命令と次の命令の間に、関数呼び出し命令が呼び出した関数の処理が終了した後にリターンすべき場所を特定するための識別ラベルを挿入する。実行時に識別ラベルの絶対アドレスを算出して、保持するように変換対象プログラムを変換する。さらに、実行時にリターン命令がリターン先として指し示すアドレスが、リターンすべきアドレス(算出して保持している変換対象プログラム実行時の識別ラベルの絶対アドレス)と一致しているかを判定して一致する場合には識別ラベルにジャンプし、一致しない場合にはプログラムを終了させるように変換対象プログラムを変換することで、リターンアドレスの改ざんを検知して不正なプログラムの実行を未然に防止する。
【選択図】図1
An object of the present invention is to prevent an unauthorized program from being executed by detecting falsification of a return address due to an attack using a vulnerability of software.
The present invention provides an identification label for specifying a place to return after the processing of a function called by a function call instruction is completed between a function call instruction included in a conversion target program and the next instruction. insert. The conversion target program is converted so that the absolute address of the identification label is calculated and held at the time of execution. In addition, if the address indicated by the return instruction at the time of execution matches the address to return (the absolute address of the identification label at the time of execution of the conversion target program that is calculated and held) and matches In this case, the conversion target program is converted so as to jump to the identification label and terminate the program if they do not match, thereby detecting the alteration of the return address and preventing the execution of an unauthorized program.
[Selection] Figure 1

Description

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

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

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

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

特許文献2には、バッファオーバーフローによる不正なプログラムの実行を防止する手段を備えるプロセッサが記載されている。   Patent Document 2 describes a processor including means for preventing execution of an illegal 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 the return address to an illegal address using the vulnerability of the software. For example, if the shared library is position-independent coded, the absolute address is resolved by dynamic linking when the executable file is executed. In the inventions described in Patent Document 1 and Patent Document 2, Since it is assumed that the absolute address indicating the program called in the main process is all known before the execution of the main process, even if the return address is rewritten to an invalid address, it cannot be handled.

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

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

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

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

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

前述の仕組みを実現して課題を解決するために、本発明は、変換対象プログラムの開始アドレス及び変換対象プログラムにリンクされる共有ライブラリの開始アドレスをメモリマップに基づいて算出し、保持する命令を、変換対象プログラムの実行開始直後に、変換対象プログラムから、この命令を呼び出すことができるように変換対象プログラムに挿入することを特徴とする。なお、本願書面においては、「変換対象プログラムの開始アドレス及び変換対象プログラムにリンクされる共有ライブラリの開始アドレスをメモリマップに基づいて算出し、保持する命令」を「ロードアドレス算出命令」と記述する。以下において同様である。   In order to solve the problem by realizing the above-described mechanism, the present invention calculates an instruction to store and calculate 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. Immediately after the start of execution of the conversion target program, the conversion target program is inserted into the conversion target program so that the instruction can be called. In this document, “an instruction to calculate and hold 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” is described 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 the conversion target program, and specifies a place to return after processing of the function called by the function call instruction is completed. In this case, an identification label is generated, and the identification label is inserted between the detected function call instruction and the next instruction.

前述の仕組みを実現して課題を解決するために、本発明は、変換対象プログラムに含まれるリターン命令を検出し、検出したリターン命令を、変換対象プログラム実行時にリターン命令がリターン先として指し示すアドレスが識別ラベルのアドレスから算出したリターンすべき絶対アドレスと一致しているかを判定して一致しない場合には変換対象プログラムを終了させるリターンアドレスチェック命令へ分岐する命令、に書き換えることを特徴とする。なお、本願書面においては、「変換対象プログラム実行時にリターン命令がリターン先として指し示すアドレスが識別ラベルアドレスから算出したリターンすべきアドレスと一致しているかを判定して一致しない場合には変換対象プログラムを終了させる命令」を「リターンアドレスチェック命令」と記述する。以下において同様である。   In order to realize the above-described mechanism and solve the problem, the present invention detects a return instruction included in the conversion target program, and the detected return instruction has an address that the return instruction indicates as a return destination when the conversion target program is executed. It is characterized in that it is rewritten to an instruction that branches to a return address check instruction that terminates the program to be converted if it does not coincide with the absolute address to be returned calculated from the address of the identification label. Note that in this document, “when the conversion target program is executed, it is determined whether the address indicated by the return instruction as the return destination matches the address to be returned calculated from the identification label address. “End instruction” is described as “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 solve the problem by realizing the above-described mechanism, 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 realize the above-described mechanism and solve the problem, the present invention determines whether or not the conversion target program starts normally. When the conversion target program starts normally, the conversion of the program ends, and when the conversion target program does not start normally. Is characterized by instructing reacquisition of the identification label address, instructing update of the return address check instruction, and performing a process of determining whether or not normal activation is performed again.

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

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

本発明の実施の形態について図面を参照して説明する。なお、各図において同一又は相当部分には同一の符号を付し、重複する説明を省略する。   Embodiments of the present invention will be described with reference to the drawings. In addition, in each figure, the same code | symbol is attached | subjected to the same or an equivalent part, and the overlapping description is abbreviate | omitted.

(第1実施形態)
本実施形態に係る変換装置は、ソフトウェアの脆弱性を利用した攻撃によるリターンアドレスの改ざんを検知して停止するようにプログラムを変換する変換装置である。
(First embodiment)
The conversion device according to the present embodiment is a conversion device that converts a program so as to detect and stop falsification 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 apparatus 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 insertion unit 130, a return instruction rewrite 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 relationship information generation unit 100 relates to an executable object file that configures the conversion target program, and includes relationship information that indicates a relationship in which a directory in which the source file exists, an object file that configures the source file, and a symbol name are associated with each other. 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 start of execution of the conversion target program. .

コンパイラ120は、変換対象プログラムのソースプログラムを実行可能ファイル及び共有ライブラリなどのオブジェクトファイルまたはアセンブリプログラムに変換する。   The compiler 120 converts the source program of the conversion target program into an executable file and an object file such as 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, generates an identification label for specifying a place to return after the processing of the function called by the function call instruction is completed, and detects it The function has 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 and associating the acquired address with the identification label and holding it as an identification label address.

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

図1に示す変換装置10は、図2に示すハードウェア構成20を有する。図2に示すように、変換装置10は、物理的には、中央演算装置(CPU)210、入力装置220、出力装置230、主記憶装置(RAM/ROM)240、補助記憶装置250等を含むコンピュータシステムとして構成される。また、一時的な記憶回路としてCPU内に複数のレジスタ260を有する。   A conversion apparatus 10 shown in FIG. 1 has a 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. Configured as a computer system. In addition, the CPU has a plurality of registers 260 as temporary storage circuits.

変換装置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 the central processing unit (CPU) 210 by causing the central processing unit (CPU) 210 and the main storage unit (RAM / ROM) 240 shown in FIG. This is realized by operating the input device 220 and the output device 230 and reading / writing data from / 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 apparatus 10 according to this embodiment will be described. FIG. 3 is a flowchart showing the operation of the conversion apparatus 10 according to the present embodiment. As shown in FIG. 3, the processing performed by the conversion apparatus 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 understanding the description, the following is the Linux (registered trademark) as the operation system, the C language as the programming language, the GNU compiler collection (hereinafter referred to as GCC) as the compiler, and the file format generated by the compiler. Although the description will be made assuming that ELF is used, the same is true if the computer behaves in the same manner.

変換装置10は、例えば、変換対象プログラム及び変換対象プログラムにリンクされるプログラムをプロセス空間にロードした後に明示的に動作の開始を指示するなどによって、図3に示す動作を開始する。   The conversion apparatus 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 apparatus 10 according to this embodiment will be described with reference to the flowchart shown in FIG.

変換装置10の動作の開始にあたっては、変換装置10に対して変換対象プログラムを指定する。変換装置10で起動する変換プログラムに引数として、変換対象プログラムであるすべての実行可能ファイルのディレクトリフルパス、変換対象プログラムであるすべての実行可能ファイルのソースファイルのディレクトリフルパスを与えることで指定する。また、実行可能ファイルにリンクされ、かつ変換対象プログラムであるすべての共有ライブラリについても、同様に、オブジェクトファイルのディレクトリフルパス、ソースファイルのディレクトリフルパスを引数として与える。このように引数を与える理由は、同一の共有ライブラリが複数の実行可能ファイルとリンクされる可能性があるため、共有ライブラリ内の関数に対するリターンアドレスチェック命令に不足が生じないようにするためである。   When starting the operation of the conversion device 10, a conversion target program is designated for the conversion device 10. It is specified by giving the directory full path of all executable files that are conversion target programs and the directory full path of the source file of all executable files that are conversion target programs as arguments to the conversion program started by the conversion apparatus 10. Similarly, the directory full path of the object file and the directory 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 program. The reason for giving the argument in this way is to prevent a shortage of return address check instructions for the 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 in FIG. 3, the conversion apparatus 10 performs a sequential conversion process on all executable files that are conversion target programs specified as described above. The following processing is performed by taking over the directory full path information in which the executable file of the conversion target program, which is given at the start of the operation of the conversion apparatus 10, exists. First, the processing of the information acquisition processing block B10 will be described.

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

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

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

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

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

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

次に、関係情報生成部100は、図4に示す関係情報を生成するためにシンボル名調査を行う。関係情報生成部100は、図4に示すソースファイルディレクトリ41について、順次、図6にフローチャートで示されるシンボル名調査を実行する。ソースファイルディレクトリ41について、ディレクトリ内の要素がなくなるまで(S601)処理を実行する。   Next, the relationship information generation unit 100 performs a symbol name check to generate the relationship information shown in FIG. The relationship information generation unit 100 sequentially performs a symbol name check shown in the flowchart of FIG. 6 for the source file directory 41 shown in FIG. The process is executed for 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) for the directory is executed. If the element is not a directory, the process proceeds to the determination process of S607.

S607の処理では、要素がオブジェクトファイルかどうかを判定する。ファイル名の拡張子が.oである場合、オブジェクトファイルと判定する。要素がオブジェクトファイルであると判定した場合には、構成オブジェクトファイル42として図4に示すようにソースファイルディレクトリ41と関係づける。その後、S609の処理に移行する。要素がオブジェクトファイルでないと判定した場合にはディレクトリ内の次の要素に移行する。   In the process of S607, it is determined whether the element is an object file. File name extension is. If it is o, it is determined as an object file. If it is determined that the element is an object file, the configuration object file 42 is related to the source file directory 41 as shown in FIG. Thereafter, the process proceeds 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 acquired. In Linux (registered trademark), a symbol can be acquired by the nm command. A process of associating the acquired symbol name 43 with the configuration object file 42 as shown in FIG. 4 (S611).

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

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

次に、ロードアドレス算出命令挿入部110が、ロードアドレス算出命令挿入処理(S305)を行う。ロードアドレス算出命令挿入処理(S305)は、変換対象プログラムの実行開始直後に、変換対象プログラムからロードアドレス算出命令を呼び出すことができるように変換対象プログラムにコードを挿入する処理である。   Next, the load address calculation instruction insertion unit 110 performs a load address calculation instruction insertion process (S305). The load address calculation instruction insertion process (S305) is a process for inserting 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.

位置独立コード化された共有ライブラリなどはロードされないとアドレスが確定しない。このため、ロードアドレス算出命令挿入部110は、変換対象プログラムの実行開始直後に、変換対象プログラムから、ロードアドレス算出命令を呼び出すことができるように変換対象プログラムにコードを挿入することでロード時の開始アドレスを取得できるようにする。   Addresses are not fixed unless shared libraries that are position-independent coded are loaded. Therefore, 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. Make the start address available.

図7は、ロードアドレス算出命令挿入処理を示すフローチャートである。図7に示すフローチャートに従って、ロードアドレス算出命令挿入処理について説明する。   FIG. 7 is a flowchart showing load address calculation instruction insertion processing. The load address calculation instruction insertion process 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 acquired. In the memory map, the executable file is always the first element, so the first element of the object file array always corresponds to the executable file. When the processing of S701 ends, the process proceeds to S703.

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

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

S709の処理では、要素がソースファイルかどうかを判定する。例えば、C言語で書かれたソースファイルは拡張子が、「.C」のファイルである。要素がソースファイルでなければ次の要素に移行する。要素がソースファイルならばファイルをオープンしてS711の処理に移行する。   In step S709, it is determined whether the element is a source file. For example, a source file written in C language is a file with 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 source file is sequentially read to the end and the main function is found (S713). If the main function is found, a code for calling the load address calculation instruction is described at the beginning of the main function (the line immediately after the main function of the source file is described) (S715). As a result, when the main function is called when the converted program is executed, the load address calculation instruction is first called.

S715の処理では、main関数にロードアドレス算出命令を呼び出すコードを新たに記述した。S717の処理では、この新たに呼び出されるロードアドレス算出命令の実体を含むソースファイルと共にコンパイルとリンクを行う必要があるため、Makefileの書き換えを行う。以上が、情報取得処理ブロックB10の処理である。   In the process of S715, a code for calling a load address calculation instruction is newly described in the main function. In the process of S717, since it is necessary to compile and link together with the source file containing the substance of the newly called load address calculation instruction, the Makefile is rewritten. 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 unit 110 completes the load address calculation instruction insertion process (S305), the conversion apparatus 10 compiles (S307) the Makefile rewritten by the compiler 120 and creates an executable file. At this time, the conversion apparatus 10 outputs the assembly file to the source files in all the source file directories 41 of FIG. 4 as the 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 execution of the program after conversion will be described. The load address calculation command calculates the start address of the conversion target program and the start address of the program linked to the conversion target program, concatenates them into one character string in ascending order of address, and outputs them to a file. The character string is stored as a new memory area in the process space as readable and writable, 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 activated process is acquired. The process ID can be acquired by the getpid function in the C language. When the process of S801 is completed, the process proceeds to S803.

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

S805の処理では、取得したメモリマップについて1行目から順に取得して、アクセス権限がr−xp(読み込み可、書き込み不可、実行可)であるかどうか判定(S807)することで、実行可能ファイルと共有ライブラリを抽出する。   In the processing of S805, the acquired memory map is acquired in order from the first line, and it is determined whether the access authority 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 process of S809, the start address (see symbol a in FIG. 5) of the r-xp line is acquired, and a character string in which the acquired 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 the character string generated in the later processing. For example, for the number of bytes, the address is corrected to 16 bytes by padding with zeros. Since the byte order (endian) differs depending on the processor and platform, a character string suitable for the environment is generated. Information on the endian type is described in the ELF header. When the processing of S809 is completed for all r-xp rows in the memory map, the processing proceeds to S811.

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

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

このようにロードアドレス算出命令によって、変換対象プログラムの開始アドレス及び変換対象プログラムにリンクされる共有ライブラリの開始アドレスをメモリマップに基づいて算出し、保持する。   As described above, 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 being converted by the conversion device 10 in consideration of the ease of understanding the following explanation, An outline of the relationship between the processing of S309 to S313 in the instruction generation / insertion processing block B20 will be described.

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

図9に沿って変換された後の変換対象プログラムの動作について概要を説明する。呼び出し元のアセンブリ言語で記述されたソースコード(以下、アセンブリコードという)でcall myfuncで関数myfuncが呼び出されると、呼び出し先アセンブリファイルの関数myfuncに処理が移る。呼び出し先アセンブリファイルでは、関数myfuncの処理終了後に呼び出し元に戻るためのret命令がリターンアドレスチェック命令へのjump命令(903)に書き換わっている。このため、関数myfuncの処理が終了すると、同じ呼び出し先アセンブリファイルに記述されたリターンアドレスチェック命令(905)に処理が移る。リターンアドレスチェック命令では、チェックロジックに基づいてリターン先が正しいかどうかを判定し、正しくないと判定した場合にはプロセスを終了し、正しいと判定した場合には呼び出し元アセンブリファイルのcall命令の次の行に記述された識別ラベルにジャンプする。   The 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 with call myfunc in the source code (hereinafter referred to as assembly code) described in the calling source assembly language, the process moves to the function myfunc in the called assembly file. In the callee assembly file, a ret instruction for returning to the caller after the processing of the function myfunc is rewritten as a jump instruction (903) as a return address check instruction. For this reason, when the process of the function myfunc ends, the process moves to the return address check instruction (905) described in the same call destination assembly file. In the return address check instruction, it is determined whether or not the return destination is correct based on the check logic. When it is determined that the return destination is not correct, the process is terminated, and when it is determined correct, the call instruction in the caller assembly file is followed by the call instruction. Jumps 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 conversion and the processing from S309 to S313 of the instruction generation / 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. In the identification label generation / insertion process (S309), a function call instruction is detected from the call source assembly file, and an identification label (901) for specifying a place to return after the processing of the function called by the function call instruction is completed. An 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 called 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 called assembly file.

前述のように、本実施例では、呼び出し先アセンブリファイルにリターンアドレスチェック命令を記述することで、リターン先が正しいかどうかの判定を実現している。しかし、呼び出される関数が標準関数の場合、標準関数はバイナリで提供されるので、直接アセンブリファイルにリターンアドレスチェック命令を記述することができない。そこで、第1実施形態では、変換対象プログラムが使用する標準関数については、公開されているソースコードを参考にして同じ動作をする自作した標準関数を新たな共有ライブラリとして配置することで、直接アセンブリファイルにリターンアドレスチェック命令を記述できるようにする。この方法によれば、リターンアドレスの改ざんを完全に防ぐことができる。なお、バイナリで提供される標準関数をそのまま使用する実施形態を第2実施形態として後述する。   As described above, in this embodiment, the return address check instruction is described in the call destination assembly file, thereby determining whether the return destination is correct. However, when the function to be called is a standard function, since the standard function is provided in binary, the return address check instruction cannot be described directly in the assembly file. Therefore, in the first embodiment, the standard function used by the conversion target program is directly assembled by arranging a self-made standard function that performs the same operation with reference to the public source code as a new shared library. Enable return address check instructions to be written in the file. According to this method, alteration of the return address can be completely prevented. An embodiment that uses a standard function provided in binary 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 / insertion unit 130 performs identification label generation / insertion processing (S309). The identification label generation / insertion processing (S309) detects a function call instruction included in the conversion target program, and generates an identification label for specifying a place to return after the processing of the function called by the function call instruction is completed. In this process, an identification label is inserted 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 / insertion process (S309) and the return instruction rewrite process (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 / insertion process (S309) will be described with reference to FIG.

識別ラベル生成挿入部130は、識別ラベル生成挿入処理(S309)を行う。識別ラベル生成挿入処理(S309)は、アセンブリファイルごとに実行される。S1001の処理では、アセンブリファイルの1行目から末尾まで順次以下の処理を行う。   The identification label generation / insertion unit 130 performs identification label generation / insertion processing (S309). The identification label generation / insertion process (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 in order to detect a function call instruction included in the conversion target program. If a call instruction is found, the process proceeds to S1005.

S1005の処理は、S1003の処理で発見したcall命令とcall命令の次の行に呼び出した関数の処理が終了した後にリターンすべき場所を特定するための識別ラベルを生成してアセンブリコードとして出力する。   In step S1005, the call instruction found in step S1003 and a function called to the next line of the call instruction are generated, and an identification label for specifying a place to return 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 process (S1005). Rewrite processing is performed by generating 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 has 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の処理に移行する。   The processing of S1101 generates a return source identification label. As long as the identification label can be identified, any rule can be used. Here, as an example, a common character string “.ATTC_RET_LB” indicating a return source identification label, a character string “35xqh754” obtained by hashing the existing source directory / usr / local / src / sample_1 /, and a source file name “Sample_1” and serial number “$ 2” are combined to generate an identification label. The same function may be called multiple times with the same assembly code, but even if the function is the same, the return source is different, and therefore processing is performed so that the identification label names do not overlap. 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 of S1101 ends, the process proceeds to S1103.

S1103とS1105の処理では、識別ラベルの挿入処理を行う。S1101の処理で生成した識別ラベルを、関数を呼び出すcall命令と次の命令との間に挿入する。S1105の処理が終了するとS1107の処理に移行する。   In the processes of S1103 and S1105, an identification label insertion process 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 process of S1105 ends, the process proceeds to S1107.

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

次に、図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, 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 in order to detect a return instruction included in the conversion target program. If a ret instruction is found, the process proceeds to S1009.

S1009の処理は、検出したリターン命令をリターンアドレスチェック命令へ分岐する命令に書き換える。具体的には、図9で示したように、ret命令を同じソースファイルに記述されたリターンアドレスチェック命令のラベルにジャンプするjmp命令に書き換える。   In the process of S1009, the detected return instruction is rewritten 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 the check logic for each return source identification label to be checked. For this reason, it is necessary to assign the label name of the return address check instruction so as not to be duplicated for each function to be called. 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 assigned 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)が終了する。   The processing of S1011 is output as it is for lines that are assembly code and are neither a call instruction nor a ret instruction. The process is performed to the end of the assembly file, and the identification label generation / insertion process (S309) and the return instruction rewrite process (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). In the return address check instruction generation / insertion process (S313), a return address check instruction is generated and inserted into the conversion target program.

図12は、リターンアドレスチェック命令生成挿入処理(S313)を示すフローチャートである。関係情報生成部100が生成した関係情報(図4参照)に基づいて、すべてのソースファイルディレクトリ41について(S1201)、関係づけられた構成オブジェクトファイル42に対応(S1203)するアセンブリファイルに含まれるシンボル名43を引数として(S1205)、引数としたシンボル名に対応する関数についてのリターンアドレスチェック命令を生成して、当該関数が含まれるアセンブリファイルに出力(図9を参照)する。   FIG. 12 is a flowchart showing return address check instruction generation / insertion processing (S313). Based on the relationship information generated by the relationship information generation unit 100 (see FIG. 4), symbols included in the assembly file corresponding to the related configuration object file 42 (S1203) for all source file directories 41 (S1201). Using 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 for explaining in detail the generation of a return address check instruction, which is the processing of S1207. The return address check instruction is generated for each function corresponding to the symbol name in the assembly file. 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. Specifically, the return address check instruction is an address that the return instruction points to the register A as a return destination at the time of execution of the program after conversion. The absolute address of the identification label at the time of execution) is saved, and whether the register A and the register B coincide with each other is determined to detect falsification of the return address.

図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 / insertion process (S313) has a symbol name included in the assembly file based on the relationship information generated by the relationship information generation unit 100 as an argument. Here, the explanation will be made assuming that the symbol name of the argument is print_msg. In the processing of S1301, the following processing is sequentially performed until the end of the elements of the return source identification label file (see FIG. 11) generated by the identification label generation / insertion unit 130.

S1303の処理では、リターン元識別ファイルに記述された関数名1109と引数としてシンボル名で与えられた関数名が一致するか判断する。一致しない場合は、リターン元識別ファイルの次の行に移って処理を繰り返す。一致する場合は、S1305の処理に移行する。   In the processing 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, move to the next line in the return source identification file and repeat the process. If they match, the process proceeds to S1305.

S1305の処理では、引数としてシンボル名で与えられた関数名が、リターン元識別ファイルに記述された関数名として最初に出現した行であるかどうかを判定する。リターン元識別ラベルファイルは関数名でソートされているので、順次、ファイルを読み込むことで、関数名が最初に出現したかどうか判定できる。図11に示すリターン元識別ファイルでは、関数名print_msgは4行に渡って記述されているが、関数名でソート済みなので、リターン元識別ファイルの要素の2行目が関数名print_msgの最初に出現した行となる。S1305の処理で、引数としてシンボル名で与えられた関数名が、リターン元識別ファイルに記述された関数名として最初に出現した行であると判定されると、S1307の処理に移行する。   In the processing of S1305, it is determined whether or not the function name given by the symbol name as an argument is a line that first appears as the function name described in the return source identification file. Since the return source identification label file is sorted by function name, it is possible to determine whether the function name first appears by reading the file sequentially. In the return source identification file shown in FIG. 11, the function name print_msg is described over four lines, but since it has been sorted by function name, the second line of elements of the return source identification file appears first in the function name print_msg. Line. If it is determined in S1305 that the function name given as an argument as the argument is the first occurrence of the function name described in the return source identification file, the process proceeds to 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 it is a return address check instruction for the 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 in FIG. 11 is ATTC_RET_LB_35xqh754_sample_1 $ print_msg. In the processing from S1309, the check logic for each return source identification label is described for the function after this label. When the process of S1307 ends, the process proceeds to S1309.

S1309の処理は、スタックをレジスタAに退避する命令を出力する。変換後のプログラムが起動した場合、リターンアドレスチェック命令が呼び出されたタイミングでスタックポインタが指しているのはリターンアドレスになるので、リターンアドレスがレジスタAに格納される。S1309の処理が終了するとS1311の処理に移行する。   In step S1309, an instruction to save the stack to the register A is output. 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 process of S1309 ends, the process proceeds to S1311.

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

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

S1313からS1319の処理は、識別ラベルが位置独立コード化されたオブジェクトファイル内に存在する場合の処理である。この場合、識別ラベルのアドレスはオフセット値である。よって、識別ラベルの絶対アドレスは、識別ラベルが記述されたロードされたオブジェクトファイルの開始アドレスに、リターン元識別ファイル中の識別ラベルのオフセット値を加算することで求められる。   The processing from S1313 to S1319 is processing when the identification label exists in the object file that has been position-independent coded. 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 it in the register B.

変換後のプログラム実行時には、実行直後に、ロードアドレス算出命令(図8)によって、変換対象プログラムの開始アドレス及び変換対象プログラムにリンクされる共有ライブラリの開始アドレスがメモリマップに基づいて取得され、これら開始アドレスを連結した文字列が読み取り専用でメモリ領域に書き込まれる。そして、このメモリ領域の先頭アドレスが開始アドレス格納変数に保持される。識別ラベルのアドレスがオフセット値である場合、リターンアドレスチェック命令生成挿入部150は、ロードアドレス算出命令(図8)によって取得され、保持されているアドレスを使ってリターンアドレスのチェックを行う命令を生成して挿入する。   When executing the program after conversion, immediately after execution, the start address of the conversion target program and the start address of the shared library linked to the conversion target program are acquired based on the memory map by the load address calculation instruction (FIG. 8). The character string concatenated with the start address 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 processing of S1313 outputs an instruction to transfer the reference destination address of the start address storage variable (the start address of the memory area where the character string concatenated with the start address of the loaded object file is written) to the register B.

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

S1319の処理は、レジスタBにリターン元識別ラベルファイルに記述される当該識別ラベル1111に対応するアドレス値1113を加算する命令を出力する。変換後のプログラム実行時において、後述する識別ラベルアドレス取得部160が行う識別ラベルアドレス取得処理(S315)によって、アドレス値1113にはnmコマンドで取得した識別ラベルのアドレスが記述されるが、S1311の処理での判定通り、識別ラベルのアドレス値1113はオフセット値をとる。S1319の処理は、ロードされたオブジェクトファイルの開始アドレスと識別ラベルのアドレス値(オフセット)を加算することで識別ラベルの絶対アドレスを算出する命令を生成している。   In the processing of S1319, an instruction to add the address value 1113 corresponding to the identification label 1111 described in the return source identification label file is output to the register B. At the time of executing the program after conversion, the address of the identification label acquired by the nm command is described in the address value 1113 by the identification label address acquisition process (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. In the process of S1319, an instruction for calculating the absolute address of the identification label is generated 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 S1311 that the object file in which the identification label is described is not position-independent coded, the process proceeds to S1321. In this case, the address of the identification label is an absolute address. In the processing of S1321, it is determined whether the assembly file is a self-made so source.

当該アセンブリファイルが自作soソースの場合は、実行可能ファイルの中で、自作の共用ライブラリの関数を呼び出す場合に該当する。リターン元識別ラベルファイルに記述される当該識別ラベル1111に対応するアドレス値1113は、実行可能ファイル内に存在するので絶対アドレスとなり、そのままレジスタBに転送する命令を出力(S1323)する。   If the assembly file is a self-made so source, this corresponds to calling a function of a self-made shared library in the 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 an instruction to transfer to the register B is output as it is (S1323).

当該アセンブリファイルが自作soソースではない場合は、実行可能ファイルの中で、実行可能ファイル内の関数を呼び出す場合に該当する。実行時に識別ラベルのアドレスを取得してレジスタBに転送する命令を出力(S1325)する。例として、leaq .ATTC_RET_LB_35xqh754_sample_1$1(%rip),%r11となる。本実施例では、例示した関数を利用する。   If the assembly file is not a self-made so-source, this corresponds to calling a function in the executable file 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 illustrated function is used.

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

当該関数に関しての処理が最後まで終わる(S1331)と、NGラベルへジャンプする命令を出力(S1335)する。ジャンプ先のNGラベル先には、プロセスを終了する命令が記述される。以上が、命令生成挿入処理ブロックB20の処理である。   When the processing relating to the function is completed to the end (S1331), an instruction to jump to the NG label is output (S1335). An instruction to end the process is described in the jump destination NG label. 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 it as the identification label address (S315), and determines whether the conversion target program starts normally If it starts normally, it ends the conversion of the program.If it does not start normally, it instructs the re-acquisition of the identification label address, instructs the update of the return address check instruction, and determines whether it starts normally again. It consists of a return address check instruction update process (S317) for performing a determination process.

チェック処理ブロックB30に処理が移行すると、まず1回、実行可能ファイルと共用ライブラリを作成する。チェック処理ブロックB30は、命令生成挿入処理ブロックB20の処理で書き換えられたプログラムが正常に起動することを確認するためである。   When the processing moves 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 by 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 process (S315). The identification label address acquisition unit 160 executes an identification label address acquisition process (S315). Based on the relationship information generated by the relationship information generation unit 100 (see FIG. 4), the corresponding object file 40 is acquired (S1403) for all the source file directories 41 (S1401). From each object file, the nm command is used to obtain the symbol name and the address after creation of the executable file for the symbol (S1405). The address value 1113 of the return source identification file is rewritten for those that match 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 return address check instruction update processing (S317). The return address check instruction update processing unit 170 executes a return address check instruction update process (S317). In order to reflect the address value 1113 of the return source identification file rewritten to the address value acquired by the identification label address acquisition process (S315), the return source check file is executed again by executing the return address check instruction generation (FIG. 13). A return address check instruction in which an address value at the time of execution is embedded is generated as the address value 1113. Further, when the return address check instruction is inserted into the assembly file by the return address check instruction generation / insertion process (S313), the file size becomes larger than the initial size, so the address value of the inserted identification label changes. In this case, the return address takes a value different from the original assumption, and it is determined that the return address has been tampered with, and the process ends abnormally. Therefore, in order to deal with such a situation, create an executable file and a shared library and check whether it works normally. If it starts normally, it ends the conversion of the program, and if it does not start normally Then, an instruction to reacquire the identification label address is issued, an instruction to update the return address check instruction is issued, and a process of determining whether or not normal activation is performed again is performed.

図15に沿って、リターンアドレスチェック命令更新処理(S317)を説明する。関係情報生成部100が生成した関係情報(図4参照)に基づいて、すべてのソースファイルディレクトリ41について(S1501)、関係づけられた構成オブジェクトファイル42に対応(S1503)するアセンブリファイル名を引数として、引数としたアセンブリファイルに記述されたリターンアドレスチェックロジックを更新(S1505)する。その後、実行可能ファイル及び共用ライブラリを作成(S1507)して、実行可能ファイルを起動(S1509)する。正常起動したか判定(S1511)を行い、正常起動すればリターンする。正常起動しない場合は、再度、識別ラベルアドレス取得処理(S315)に戻って実行を続ける。   The return address check instruction update process (S317) will be described with reference to FIG. Based on the relationship information generated by the relationship information generation unit 100 (see FIG. 4), for all source file directories 41 (S1501), the assembly file name corresponding to the related configuration object file 42 (S1503) is used as an argument. The return address check logic described in the assembly file as an argument is updated (S1505). Thereafter, an executable file and a shared library are created (S1507), and the executable file is activated (S1509). It is determined whether or not it has been normally started (S1511). If it does not start normally, the process returns to the identification label address acquisition process (S315) again and continues 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 return address check logic update (S1505) will be described with reference to FIG. In the process of S1601, the assembly file specified by the argument is opened and rewritten sequentially from the first line to the end. In the processing of S1603, it is determined whether or not the check logic is described. If it is not a 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 a description part of the check logic, it is determined whether the return address check label is described for each function (S1607). If it is not a return address check label, the process proceeds to the next line (S1613). If it is a return address check label, a function name is acquired from the label (S1609), and a return address check instruction generation (FIG. 13) is executed using the acquired 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, the processing returns to FIG. 3 and shifts to the conversion processing of the next conversion target program designated by the argument (S301). When the conversion process is completed for all the conversion target programs, conversion of the conversion target program by the conversion device 10 is completed.

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

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

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

図17は、第2実施形態での識別ラベル生成挿入処理を示すフローチャートである。第1実施形態での識別ラベル生成挿入処理(図10)と異なり、call命令を検出(S1003)した後、呼び出される関数が標準関数かどうかの判定(S1713)を行う。標準関数でない場合には第1実施形態と同様の処理となる。標準関数の場合、標準ライブラリ関数識別ラベル出力(S1715)に移行する。S1717の処理は、アセンブリファイル別に使用される標準関数のリストを生成する。同じ標準関数(例えば、printf)であっても記述されているアセンブリファイルが異なると標準関数の処理終了後のリターン元のアドレスが異なるからである。   FIG. 17 is a flowchart showing identification label generation / insertion processing in the second embodiment. Unlike the identification label generation / insertion process (FIG. 10) in the first embodiment, after the call instruction is detected (S1003), it is determined whether the function to be called is a standard function (S1713). If it is not a standard function, the processing is the same as in the first embodiment. In the case of a standard function, the process proceeds to standard library function identification label output (S1715). In step S1717, a list of standard functions used for each assembly file is generated. This is because even if the same standard function (for example, printf) is described in different assembly files, the return source address after the 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 obtaining an address of an identification label for specifying a place to return after the processing of the standard function called by the call instruction is completed and storing it in a register (S1805), and generating a label for calling the standard function Then, a command to jump to the label (S1807) is output. After the jump instruction, the identification label for specifying the place to return after the processing of the standard function called by the call instruction is output (S1809).

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

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

S2003の処理では、S1717の処理で生成されたアセンブリファイル別標準関数のリストの要素である標準関数について順次標準関数コール処理を生成する。S2005の処理では、S1807の処理で生成された標準関数の呼び出し用ラベルを出力する。S2007の処理では、当該関数をコールする命令を出力する。S2009の処理では、標準関数コール共通処理にジャンプする命令を出力する。図20に示すように、ジャンプ先の標準関数コール共通処理では、S1805の処理で実行時に取得してレジスタに格納したリターンすべき場所を特定するための識別ラベルのアドレスにジャンプする。   In the process of S2003, standard function call processes are sequentially generated for the standard functions that are elements of the list of standard functions for each assembly file generated in the process 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 for calling 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 of the jump destination, the process jumps to the address of the identification label for identifying the place to be returned acquired 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 the part that controls the conversion process centrally. The input module operates the computer system to input the program to be converted, and the output module outputs 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 insertion module, a return instruction rewrite module, an identification label address acquisition module, a return address check instruction generation insertion module, and a return address check instruction update module. Is provided. Functions realized by executing the main module, the input module, the output module, and the arithmetic processing module are the relation information generation unit 100, the load address calculation instruction insertion unit 110, the compiler 120, and the identification label generation insertion unit 130 of the conversion device 10. The return command rewriting unit 140, the return address check command generation / insertion unit 150, the identification label address acquisition unit 160, and the return address check command update unit 170 have the same functions.

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

Claims (5)

リターンアドレスの改ざんを検知して停止するようにプログラムを変換する変換装置であって、
変換対象プログラムを構成する実行可能なオブジェクトファイルについて、ソースファイルの存在するディレクトリと、ソースファイルを構成するオブジェクトファイルと、シンボル名と、が互いに紐づく関係を示す関係情報をメモリマップに基づいて生成する、関係情報生成部と、
前記変換対象プログラムの開始アドレス及び前記変換対象プログラムにリンクされる共有ライブラリの開始アドレスをメモリマップに基づいて算出し、保持する命令を、前記変換対象プログラムの実行開始直後に、前記変換対象プログラムから、この命令を呼び出すことができるように前記変換対象プログラムに挿入する、開始アドレス算出命令挿入部と、
前記変換対象プログラムに含まれる関数呼び出し命令を検出し、前記関数呼び出し命令が呼び出した関数の処理が終了した後にリターンすべき場所を特定するための識別ラベルを生成し、検出した前記関数呼び出し命令と次の命令との間に前記識別ラベルを挿入する、識別ラベル生成挿入部と、
前記変換対象プログラムに含まれるリターン命令を検出し、検出した前記リターン命令を、前記変換対象プログラム実行時に前記リターン命令がリターン先として指し示すアドレスが識別ラベルのアドレスから算出したリターンすべき絶対アドレスと一致しているかを判定して一致しない場合には前記変換対象プログラムを終了させるリターンアドレスチェック命令であって、前記リターン命令が記述されている前記変換対象プログラムに含まれる関数呼び出し命令によって呼び出される関数についてのリターンアドレスチェック命令へ分岐する命令、に書き換える、リターン命令書き換え部と、
前記変換対象プログラムを構成する実行可能なオブジェクトファイルと、ソースファイルの存在するディレクトリと、ソースファイルを構成するオブジェクトファイルに、前記関係情報で関係づけられたシンボル名に対応する関数ごとに前記リターンアドレスチェック命令を生成し、前記シンボル名に対応する関数と前記関係情報で関係づけられたソースファイルに生成した前記リターンアドレスチェック命令を記述することで、前記変換対象プログラムに前記リターンアドレスチェック命令を挿入する、リターンアドレスチェック命令生成挿入部と、
前記識別ラベルのアドレスを取得し、取得したアドレスを識別ラベルと紐づけて前記識別ラベルアドレスとして保持する、識別ラベルアドレス取得部と、
前記変換対象プログラムが正常起動するかを判定し、正常に起動した場合にはプログラムの変換を終了し、正常に起動しない場合には、前記識別ラベルアドレス取得部に前記識別ラベルアドレスの再取得を命令し、前記リターンアドレスチェック命令生成挿入部に前記リターンアドレスチェック命令の更新を命令し、再度正常起動するかを判定する処理を行なう、リターンアドレスチェック命令更新部と、
を備えることを特徴とする変換装置
A conversion device that converts a program to detect and stop falsification of a return address,
For executable object files that make up the program to be converted, relation information that indicates the relationship between the directory where the source file exists, the object file that makes up the source file, and the symbol name are generated based on the memory map A relationship information generator,
A start address of the conversion target program and a start address of a shared library linked to the conversion target program are calculated based on a memory map, and an instruction to be held is received from the conversion target program immediately after the start of execution of the conversion target program. , A start address calculation instruction insertion unit for inserting the 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, an identification label for specifying a place to return after the processing of the function called by the function call instruction is completed, and the detected function call instruction An identification label generating / inserting unit for inserting the identification label between the next instruction and
A return instruction included in the conversion target program is detected, and the detected return instruction is coincident with an absolute address to be returned calculated from an address of an identification label by an address indicated by the return instruction as a return destination when the conversion target program is executed. A return address check instruction that terminates the conversion target program if it does not match and is called by a function call instruction included in the conversion target program in which the return instruction is described A return instruction rewriting unit that rewrites the instruction to branch to the return address check instruction of
The return address for each function corresponding to the symbol name related to the executable object file constituting the conversion target program, the directory in which the source file exists, and the object file constituting the source file by the relation information. Generate a check instruction and insert the return address check instruction in the conversion target program by describing the generated return address check instruction in the source file associated with the function corresponding to the symbol name and the relation information A return address check instruction generation insertion unit,
An identification label address acquisition unit that acquires an address of the identification label, associates the acquired address with an identification label, and holds the identification label address;
It is determined whether or not the conversion target program starts normally. When the conversion target program starts normally, the conversion of the program is terminated, and when the conversion target program does not start normally, the identification label address acquisition unit reacquires the identification label address. A return address check instruction update unit for instructing to update the return address check instruction to the return address check instruction generation / insertion unit and determining whether to normally start again;
A conversion device comprising:
前記リターンアドレスチェック命令生成挿入部が生成する前記リターンアドレスチェック命令は、変換対象プログラム実行時に、関数呼び出し命令が呼び出した関数の処理が終了した後にリターンすべき場所を特定するための識別ラベルが記述されたファイルが位置独立コード化されている場合には前記識別ラベルが記述されたファイルの開始アドレスに前記識別ラベルのオフセット値を取得して加算することで、位置独立コード化されていない場合には識別ラベルのアドレスを取得することで、リターンすべきアドレスを算出する、
ことを特徴とする請求項1に記載の変換装置
The return address check instruction generated by the return address check instruction generation / insertion unit describes an identification label for specifying a place to return after the processing of the function called by the function call instruction is completed when executing the conversion target program. If the recorded file is position-independent coded, the offset value of the identification label is obtained and added to the start address of the file in which the identification label is described, so that Calculates the address to return by obtaining the address of the identification label,
The conversion device according to claim 1,
前記識別ラベル生成挿入部は、検出した関数呼び出し命令が呼び出す関数が標準関数である場合には、前記標準関数を呼び出す命令を、前記標準関数の処理が終了した後にリターンすべき場所を特定するための識別ラベルの実行時のアドレスを取得してレジスタに格納する命令及び前記標準関数に分岐する命令に書き換え、前記標準関数に分岐する命令と次の命令との間に前記識別ラベルを挿入する処理を、
前記リターンアドレスチェック命令生成挿入部は、前記標準関数の処理が終了した後に前記識別ラベル生成挿入部がレジスタに格納したアドレスへリターンする命令を生成し、変換対象プログラムに挿入する処理を、
更に備えることを特徴とする請求項1又は請求項2に記載の変換装置
The identification label generation / insertion unit, when the function called by the detected function call instruction is a standard function, specifies a place where the instruction to call the standard function is to be returned after the processing of the standard function is completed. Processing for acquiring the address at the time of execution of the identification label of the first and second instructions and rewriting the instruction to store in the register and the instruction branching to the standard function, and inserting the identification label between the instruction branching to the standard function and the next instruction The
The return address check instruction generation / insertion unit generates an instruction to return to the address stored in the register by the identification label generation / insertion unit after the processing of the standard function is completed, and inserts the conversion target program into the conversion target program.
The conversion device according to claim 1, further comprising:
コンピュータに、
リターンアドレスの改ざんを検知して停止するようにプログラムの変換を実行させる変換プログラムであって、
変換対象プログラムを構成する実行可能なオブジェクトファイルについて、ソースファイルの存在するディレクトリと、ソースファイルを構成するオブジェクトファイルと、シンボル名と、が互いに紐づく関係を示す関係情報をメモリマップに基づいて生成する、関係情報生成処理ステップと、
前記変換対象プログラムの開始アドレス及び前記変換対象プログラムにリンクされる共有ライブラリの開始アドレスをメモリマップに基づいて算出し、保持する命令を、前記変換対象プログラムの実行開始直後に、前記変換対象プログラムから、この命令を呼び出すことができるように前記変換対象プログラムに挿入する、開始アドレス算出命令挿入処理ステップと、
前記変換対象プログラムに含まれる関数呼び出し命令を検出し、前記関数呼び出し命令が呼び出した関数の処理が終了した後にリターンすべき場所を特定するための識別ラベルを生成し、検出した前記関数呼び出し命令と次の命令との間に前記識別ラベルを挿入する、識別ラベル生成挿入処理ステップと、
前記変換対象プログラムに含まれるリターン命令を検出し、検出した前記リターン命令を、前記変換対象プログラム実行時に前記リターン命令がリターン先として指し示すアドレスが識別ラベルのアドレスから算出したリターンすべき絶対アドレスと一致しているかを判定して一致しない場合には前記変換対象プログラムを終了させるリターンアドレスチェック命令であって、前記リターン命令が記述されている前記変換対象プログラムに含まれる関数呼び出し命令によって呼び出される関数についてのリターンアドレスチェック命令へ分岐する命令、に書き換える、リターン命令書き換え処理ステップと、
前記変換対象プログラムを構成する実行可能なオブジェクトファイルと、ソースファイルの存在するディレクトリと、ソースファイルを構成するオブジェクトファイルに、前記関係情報で関係づけられたシンボル名に対応する関数ごとに前記リターンアドレスチェック命令を生成し、前記シンボル名に対応する関数と前記関係情報で関係づけられたソースファイルに生成した前記リターンアドレスチェック命令を記述することで、前記変換対象プログラムに前記リターンアドレスチェック命令を挿入する、リターンアドレスチェック命令生成挿入処理ステップと、
前記識別ラベルのアドレスを取得し、取得したアドレスを識別ラベルと紐づけて前記識別ラベルアドレスとして保持する、識別ラベルアドレス取得処理ステップと、
前記変換対象プログラムが正常起動するかを判定し、正常に起動した場合にはプログラムの変換を終了し、正常に起動しない場合には、前記識別ラベルアドレス取得処理ステップを実行して前記識別ラベルアドレス再取得し、前記リターンアドレスチェック命令生成挿入処理ステップを実行して前記リターンアドレスチェック命令新し、再度正常起動するかを判定する処理を行なう、リターンアドレスチェック命令更新処理ステップと、
を実行させる変換プログラム
On the computer,
A conversion program that executes conversion of a program so as to detect and stop falsification of a return address,
For executable object files that make up the program to be converted, relation information that indicates the relationship between the directory where the source file exists, the object file that makes up the source file, and the symbol name are generated based on the memory map A relationship information generation processing step;
A start address of the conversion target program and a start address of a shared library linked to the conversion target program are calculated based on a memory map, and an instruction to be held is received from the conversion target program immediately after the start of execution of the conversion target program. , A start address calculation instruction insertion processing step for inserting the 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, an identification label for specifying a place to return after the processing of the function called by the function call instruction is completed, and the detected function call instruction An identification label generation / insertion processing step of inserting the identification label with a next instruction;
A return instruction included in the conversion target program is detected, and the detected return instruction is coincident with an absolute address to be returned calculated from an address of an identification label by an address indicated by the return instruction as a return destination when the conversion target program is executed. A return address check instruction that terminates the conversion target program if it does not match and is called by a function call instruction included in the conversion target program in which the return instruction is described A return instruction rewrite processing step that rewrites the instruction to branch to the return address check instruction of
The return address for each function corresponding to the symbol name related to the executable object file constituting the conversion target program, the directory in which the source file exists, and the object file constituting the source file by the relation information. Generate a check instruction and insert the return address check instruction in the conversion target program by describing the generated return address check instruction in the source file associated with the function corresponding to the symbol name and the relation information A return address check instruction generation insertion step,
An identification label address acquisition processing step of acquiring an address of the identification label and associating the acquired address with an identification label and holding the identification label address;
It is determined whether or not the conversion target program starts normally. If the conversion target program starts normally, the conversion of the program is terminated. If the conversion target program does not start normally, the identification label address acquisition processing step is executed to execute the identification label address. re preparative Tokushi, the return address check instruction generating insertion process further new the return address check instruction by executing step performs a process for determining normal starts again, and the return address check instruction updating process step,
Conversion program to execute
リターンアドレスの改ざんを検知して停止するようにプログラムを変換するプログラム変換方法であって、
リターンアドレスの改ざんを検知して停止するようにプログラムの変換を実行させる変換プログラムであって、
変換対象プログラムを構成する実行可能なオブジェクトファイルについて、ソースファイルの存在するディレクトリと、ソースファイルを構成するオブジェクトファイルと、シンボル名と、が互いに紐づく関係を示す関係情報をメモリマップに基づいて生成する、関係情報生成処理ステップと、
前記変換対象プログラムの開始アドレス及び前記変換対象プログラムにリンクされる共有ライブラリの開始アドレスをメモリマップに基づいて算出し、保持する命令を、前記変換対象プログラムの実行開始直後に、前記変換対象プログラムから、この命令を呼び出すことができるように前記変換対象プログラムに挿入する、開始アドレス算出命令挿入処理ステップと、
前記変換対象プログラムに含まれる関数呼び出し命令を検出し、前記関数呼び出し命令が呼び出した関数の処理が終了した後にリターンすべき場所を特定するための識別ラベルを生成し、検出した前記関数呼び出し命令と次の命令との間に前記識別ラベルを挿入する、識別ラベル生成挿入処理ステップと、
前記変換対象プログラムに含まれるリターン命令を検出し、検出した前記リターン命令を、前記変換対象プログラム実行時に前記リターン命令がリターン先として指し示すアドレスが識別ラベルのアドレスから算出したリターンすべき絶対アドレスと一致しているかを判定して一致しない場合には前記変換対象プログラムを終了させるリターンアドレスチェック命令であって、前記リターン命令が記述されている前記変換対象プログラムに含まれる関数呼び出し命令によって呼び出される関数についてのリターンアドレスチェック命令へ分岐する命令、に書き換える、リターン命令書き換え処理ステップと、
前記変換対象プログラムを構成する実行可能なオブジェクトファイルと、ソースファイルの存在するディレクトリと、ソースファイルを構成するオブジェクトファイルに、前記関係情報で関係づけられたシンボル名に対応する関数ごとに前記リターンアドレスチェック命令を生成し、前記シンボル名に対応する関数と前記関係情報で関係づけられたソースファイルに生成した前記リターンアドレスチェック命令を記述することで、前記変換対象プログラムに前記リターンアドレスチェック命令を挿入する、リターンアドレスチェック命令生成挿入処理ステップと、
前記識別ラベルのアドレスを取得し、取得したアドレスを識別ラベルと紐づけて前記識別ラベルアドレスとして保持する、識別ラベルアドレス取得処理ステップと、
前記変換対象プログラムが正常起動するかを判定し、正常に起動した場合にはプログラムの変換を終了し、正常に起動しない場合には、前記識別ラベルアドレス取得処理ステップを実行して前記識別ラベルアドレス再取得し、前記リターンアドレスチェック命令生成挿入処理ステップを実行して前記リターンアドレスチェック命令新し、再度正常起動するかを判定する処理を行なう、リターンアドレスチェック命令更新処理ステップと、
をコンピュータが実行するプログラム変換方法
A program conversion method for converting a program to detect and detect alteration of a return address,
A conversion program that executes conversion of a program so as to detect and stop falsification of a return address,
For executable object files that make up the program to be converted, relation information that indicates the relationship between the directory where the source file exists, the object file that makes up the source file, and the symbol name are generated based on the memory map A relationship information generation processing step;
A start address of the conversion target program and a start address of a shared library linked to the conversion target program are calculated based on a memory map, and an instruction to be held is received from the conversion target program immediately after the start of execution of the conversion target program. , A start address calculation instruction insertion processing step for inserting the 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, an identification label for specifying a place to return after the processing of the function called by the function call instruction is completed, and the detected function call instruction An identification label generation / insertion processing step of inserting the identification label with a next instruction;
A return instruction included in the conversion target program is detected, and the detected return instruction is coincident with an absolute address to be returned calculated from an address of an identification label by an address indicated by the return instruction as a return destination when the conversion target program is executed. A return address check instruction that terminates the conversion target program if it does not match and is called by a function call instruction included in the conversion target program in which the return instruction is described A return instruction rewrite processing step that rewrites the instruction to branch to the return address check instruction of
The return address for each function corresponding to the symbol name related to the executable object file constituting the conversion target program, the directory in which the source file exists, and the object file constituting the source file by the relation information. Generate a check instruction and insert the return address check instruction in the conversion target program by describing the generated return address check instruction in the source file associated with the function corresponding to the symbol name and the relation information A return address check instruction generation insertion step,
An identification label address acquisition processing step of acquiring an address of the identification label and associating the acquired address with an identification label and holding the identification label address;
It is determined whether or not the conversion target program starts normally. If the conversion target program starts normally, the conversion of the program is terminated. If the conversion target program does not start normally, the identification label address acquisition processing step is executed to execute the identification label address. re preparative Tokushi, the return address check instruction generating insertion process further new the return address check instruction by executing step performs a process for determining normal starts again, and the return address check instruction updating process step,
Conversion method for a computer to execute
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 true JP6460433B1 (en) 2019-01-30
JP2020027512A 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
JP2020027512A (en) 2020-02-20

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
US11599348B2 (en) Container image building using shared resources
US9183007B2 (en) Dynamic determination of application server runtime classloading
TWI252431B (en) Binary translator
JP4851096B2 (en) Code rewriting
CN103093150B (en) A kind of dynamic integrity protection method based on credible chip
US9460306B1 (en) System and method for controlling access of machine code to operating system resources
JP2008502968A (en) Method for loading software comprising an intermediate object-oriented language onto a portable device
CN111095198A (en) System and method for data processing
CN105224309B (en) A kind of method and apparatus for transferring function
JP6388405B2 (en) Information processing apparatus, information processing apparatus control method, and program
US20190205528A1 (en) Automated software application verification system
US9367686B1 (en) System and method for antivirus checking of native images of software assemblies
JP6460433B1 (en) Conversion device, conversion program, and program conversion method
US20150347745A1 (en) Method for extracting executable code of application using memory dump
CN112363726A (en) Cross-kernel version compiling method and system of kernel module
KR20160143518A (en) Image forming apparatus and method for deleting application
JP6579095B2 (en) Program writing method, apparatus control method, program writing program, and apparatus control program
CN113220303A (en) Compiling method and system of kernel module
JP6834838B2 (en) Computer boot method and computer
CN112579156A (en) Processing system, processing method, processing device and processing equipment of business event
US20230418950A1 (en) Methods, Devices, and Systems for Control Flow Integrity
KR101562282B1 (en) System and Method for Verifying Integrity of an ODEX
Ivanishin et al. System-wide elimination of unreferenced code and data in dynamically linked programs

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