• Tidak ada hasil yang ditemukan

Identifying Use-After-Free Variables in Fire-and-Forget Tasks

N/A
N/A
Protected

Academic year: 2024

Membagikan "Identifying Use-After-Free Variables in Fire-and-Forget Tasks"

Copied!
35
0
0

Teks penuh

(1)

Identifying Use-After-Free Variables in Fire-and-Forget Tasks

Jyothi Krishna V S & Vassily Litvinov [email protected]

IIT Madras & Cray Inc.

June 2, 2017

(2)

begin construct in Chapel

• Creates a dynamic task with an unstructured lifetime.

Fire-and-forget

• Low synchronization and scheduling cost.

...

begin write("hello "); w r i t e (" w o r l d "); ...

E i t h e r o u t p u t s : h e l l o w o r l d w o r l d h e l l o

1/26

(3)

begin construct in Chapel

• Creates a dynamic task with an unstructured lifetime.

Fire-and-forget

• Low synchronization and scheduling cost.

...

begin write("hello "); w r i t e (" w o r l d ");

...

E i t h e r o u t p u t s : h e l l o w o r l d w o r l d h e l l o

1/26

(4)

Use-After-Free Variables

1 x SP

begin reference

{

var x = 1;

begin (ref x) {

if x == 0 t h e n w r i t e l n (" c h a o s ");

} } ...

{

var y = 0;

}

begin task has a reference to variable x (outer variable).

2/26

(5)

Use-After-Free Variables

begin reference

SP

{

var x = 1;

b e g i n ( ref x ) {

if x == 0 t h e n w r i t e l n (" c h a o s ");

} } ...

{

var y = 0;

}

End of scope of variable x and is removed from the Stack.

3/26

(6)

Use-After-Free Variables

0 y SP

begin reference

{

var x = 1;

b e g i n ( ref x ) {

if x == 0 t h e n w r i t e l n (" c h a o s ");

} } ...

{

var y = 0;

}

New variable y added.

4/26

(7)

Use-After-Free Variables

0 y SP

begin reference

{

var x = 1;

b e g i n ( ref x ) {

if x == 0 then writeln("chaos");

} } . . . . {

var y = 0;

}

Incorrect value of x seen bybegin task. We need to avoid these in our programs.

5/26

(8)

Use-After-Free Access: Sources

• Lack of synchronization.

Programs written for older versions of Chapel.

• Improper synchronization.

Programmer skills/ Programming speed / Complexity of the Program.

1

1image source:shuttershock.com 6/26

(9)

Use-After-Free Access: Sources

• Lack of synchronization.

Programs written for older versions of Chapel.

• Improper synchronization.

Programmer skills/ Programming speed / Complexity of the Program.

1

1image source:shuttershock.com 6/26

(10)

Talk Overview

• Extract relevant constructs and outer variables access into CCFG.

• Subset Representation of execution time states: Parallel Program States (PPS).

• Identify possible Use-After-Free variable accesses.

• Results and Conclusions

2

2image source:dreamstime.com

7/26

(11)

Talk Overview

• Extract relevant constructs and outer variables access into CCFG.

• Subset Representation of execution time states: Parallel Program States (PPS).

• Identify possible Use-After-Free variable accesses.

• Results and Conclusions

2

2image source:dreamstime.com

7/26

(12)

Synchronization Constructs in Chapel

• syncvariable: One-to-one synchronization

• single variable: One-to-many synchronization

• syncblock: Many-to-one synchronization.

• atomic variables.

8/26

(13)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

proc outerVarUse( ) { var x : int = 10;

var doneA$: sync bool;

begin with (ref x) { // A writeln(x);

var doneB$: sync bool;

begin with (ref x){ // B writeln(x);

doneB$ = true;

}

writeln(x);

doneA$ = true;

doneB$;

} doneA$;

begin with (in x){ // C writeln(x);

} }

• Task A Line 4.

• Task B: nested task, at Line 7.

• Task C: at Line 16. Pass by value.

• sync variables:

• doneA$: Task A and Root Task.

• doneB$: Task B and Task A.

• Outer variable: x.

9/26

(14)

Concurrent Control Flow Graph (CCFG)

• CCFG Node bounded by a Concurrent Control Flow event.

Encounter begin statement.

Read/Write on a synchronization variable.

Control Flow event

• A CCFG Node

Outer Variable Set: OV.

Synchronization type.

Synchronization variable.

• Sub graph of nested functions expanded at call site.

• A live set of sync block scope is maintained.

Safe OV accesses are removed.

10/26

(15)

CCFG

proc outerVarUse( ) { var x : int = 10;

var doneA$: sync bool;

begin with (ref x) { // A writeln(x++);

var doneB$: sync bool;

begin with (ref x){ // B writeln(x);

doneB$ = true;

}

writeln(x);

doneA$ = true;

doneB$;

} doneA$;

begin with (in x){ // C writeln(x);

}}

0

7 doneA$

10 9 Root Task

Task C 8

10

1

4

5 OV={x}

OV={x}

doneB$

2

3 OV={x}

doneB$

Task A

Task B

doneA$

6

11/26

(16)

CCFG pruning

1 Remove empty nodes at the end of each task.

Eg: Node 10.

2 Abegin task that does not contain any nested task or does not refers to any outer variable.

Eg. Task C.

3 Abegin task, in which the scope of all outer variables accessed by the task is protected by a syncblock.

Eg:

s y n c b e g i n ( r e f x ) { . . . }

• Recursively apply these three rules.

12/26

(17)

CCFG pruning

1 Remove empty nodes at the end of each task.

Eg: Node 10.

2 Abegin task that does not contain any nested task or does not refers to any outer variable.

Eg. Task C.

3 Abegin task, in which the scope of all outer variables accessed by the task is protected by a syncblock.

Eg:

s y n c b e g i n ( r e f x ) { . . . }

• Recursively apply these three rules.

12/26

(18)

Pruned CCFG

0

7

doneA$

Root Task

1

4

OV={x}

OV={x} 2

OV={x}

doneB$

Task A

Task B

doneA$

5

doneB$

• Active sync nodes: 2, 4, 7

• State Table var state doneA$ empty doneB$ empty

13/26

(19)

PPS

• A program state that captures a possible relationship between synchronization nodes.

• A Parallel Program State (PPS):

Active Sync Node (ASN): Set of nodes which are next in line to be executed.

State Table (ST): State of all live synchronization variables.

Safe access set(SV): A set of outer variable accesses which are safe.

Live access set (LA): A set of OV accesses whichmust have happened before reaching the current PPS, excluding the set of outer variable accesses in SV.

SVLA =φ.

14/26

(20)

PPS 0

0

7

doneA$

Root Task

1

4

OV={x}

OV={x} 2

OV={x}

doneB$

Task A

Task B

doneA$

5

doneB$

PPS 0:

• ASN = {2, 4, 7 }

• State Table var state doneA$ empty doneB$ empty

• SV = φ

• LA =φ

15/26

(21)

Parallel Frontier

• Checking for Use-After-Free Variable in each PPS is costly.

• Parallel Frontier: The last sync node encountered in a path in parent scope.

• Defined for every OV, x: PF(x).

• Multiple paths could lead to Multiple PF.

• The safety checks limited at PF.

Theorem

A statement that accesses an outer variable x is potentially unsafe if there exists an execution path serialization where the corresponding Parallel Frontier node is executed before the statement.

16/26

(22)

Next PPS ?

• Design a set of rules to travel in CCFG to generate next PPS.

• Rules designed based on synchronization variables’ behaviour.

• Priority : Non-blocking > blocking.

Rule (SINGLE-READ (Non blocking))

A read on asingle variable is visited if the current state of the variable is full.

Rule (READ (blocking))

A read of async variable can be visited if the current state of the variable is full. The state of the variable is changed to empty.

Rule (WRITE (blocking) )

A write on singleor syncvariable can be visited if the current state of the variable is empty. The state of the variable is changed to full.

17/26

(23)

Next PPS ?

• Design a set of rules to travel in CCFG to generate next PPS.

• Rules designed based on synchronization variables’ behaviour.

• Priority : Non-blocking > blocking.

Rule (SINGLE-READ (Non blocking))

A read on asingle variable is visited if the current state of the variable is full.

Rule (READ (blocking))

A read of async variable can be visited if the current state of the variable is full. The state of the variable is changed to empty.

Rule (WRITE (blocking) )

A write on singleor syncvariable can be visited if the current state of the variable is empty. The state of the variable is changed to full.

17/26

(24)

Next PPS ?

• Design a set of rules to travel in CCFG to generate next PPS.

• Rules designed based on synchronization variables’ behaviour.

• Priority : Non-blocking > blocking.

Rule (SINGLE-READ (Non blocking))

A read on asingle variable is visited if the current state of the variable is full.

Rule (READ (blocking))

A read of async variable can be visited if the current state of the variable is full. The state of the variable is changed to empty.

Rule (WRITE (blocking) )

A write on singleor syncvariable can be visited if the current state of the variable is empty. The state of the variable is changed to full.

17/26

(25)

Next PPS ?

• Design a set of rules to travel in CCFG to generate next PPS.

• Rules designed based on synchronization variables’ behaviour.

• Priority : Non-blocking > blocking.

Rule (SINGLE-READ (Non blocking))

A read on asingle variable is visited if the current state of the variable is full.

Rule (READ (blocking))

A read of async variable can be visited if the current state of the variable is full. The state of the variable is changed to empty.

Rule (WRITE (blocking) )

A write onsingle or syncvariable can be visited if the current state of the variable is empty. The state of the variable is changed to full.

17/26

(26)

PPS 0

0

7

doneA$

Root Task

1

4

OV={x}

OV={x} 2

OV={x}

doneB$

Task A

Task B

doneA$

5

doneB$

PPS 0:

• ASN = {2,4, 7 }

• State Table var state doneA$ empty doneB$ empty

• SV = φ

• LA =φ

18/26

(27)

Execute Node 4

0

7

doneA$

PF={x}

Root Task

1

4

OV={x}

OV={x} 2

OV={x}

doneB$

Task A

Task B

doneA$

5

doneB$

PPS 1:

• ASN = {2,5, 7}

• State Table var state doneA$ full doneB$ empty

• SV = φ

• LA = {x1, x4 }

19/26

(28)

Execute Node 7

0

7

doneA$

PF={x}

Root Task

1

4

OV={x}

OV={x} 2

OV={x}

doneB$

Task A

Task B

doneA$

5

doneB$

PPS 2:

• ASN = {2,5 }

• State Table var state doneA$ empty doneB$ empty

• SV = {x1,x4 }

• LA =φ

20/26

(29)

Execute Node 2

0

7

doneA$

PF={x}

Root Task

1

4

OV={x}

OV={x} 2

OV={x}

doneB$

Task A

Task B

doneA$

5

doneB$

PPS 3:

• ASN = { 5}

• State Table var state doneA$ empty doneB$ full

• SV = {x1,x4 }

• LA = {x2 }

21/26

(30)

Execute Node 5

0

7

doneA$

PF={x}

Root Task

1

4

OV={x}

OV={x} 2

OV={x}

doneB$

Task A

Task B

doneA$

5

doneB$

PPS 4:

• ASN = φ

• State Table var state doneA$ empty doneB$ empty

• SV = {x1,x4 }

• LA = { x2 }

Report x2.

22/26

(31)

Conditional Nodes , Loops

• Conditional Nodes: Both branches are explored separately.

• Loops:

Just OV accesses: treated as single node with OV access Source with Conditional Node

var x : int = 10;

var d o n e$: s y n c b o o l ; begin with (ref x) { // A if ( f l a g )

begin with (ref x) { // B writeln(x);

d o n e$ = t r u e ; d o n e$;

}

d o n e$ = t r u e ; }

d o n e$;

7 done$

PF={x}

else edge 2 0

1

done$

5

done$

3

OV={x}

4 done$

Task A

Task B

23/26

(32)

Optimizations & Limitations

Optimizations

• Run algorithm only for functions containing begin tasks.

• Merging multiple PPS:

Requirement: Identical State table & ASN set.

Resultant PPS: SV : SViSVj, LA :LAiLAj.

• Combine same variable accesses inside node.

Limitations: Not Handled

• Non blocking sync events: atomic

• Recursion

• Loops containing begin or synchronization node.

24/26

(33)

Optimizations & Limitations

Optimizations

• Run algorithm only for functions containing begin tasks.

• Merging multiple PPS:

Requirement: Identical State table & ASN set.

Resultant PPS: SV : SViSVj, LA :LAiLAj.

• Combine same variable accesses inside node.

Limitations: Not Handled

• Non blocking sync events: atomic

• Recursion

• Loops containing begin or synchronization node.

24/26

(34)

Results

Table : Results of running use-after-free check over Chapel test suite (version 1.11).

Total test cases 5127

Test cases with begin tasks 218

Test cases with Use-After-Free warnings 38

Number of warnings reported 437

True positives 63

Percentage of true positives 14.4%

Source Code: https://github.com/jkrishnavs/chapel

25/26

(35)

Conclusions

• Partial inter-procedural analysis to identify and report potentially dangerous Outer Variable accesses to the user.

• Results reported on chapel test suite.

• More test cases on

https://github.com/jkrishnavs/chapel_workspace

Future Work

• Atomic variable synchronization

• Loops & recursion

26/26

Gambar

Table : Results of running use-after-free check over Chapel test suite (version 1.11).

Referensi

Dokumen terkait

• If a matlab command contains many calculations, embedded functions or long variable names, it may be necessary to split the command onto multiple lines so that it can be read

The results of testing variables, namely performance, and economics, show that there is a significant influence on the user satisfaction variable, while for the variables,

Therefore, the decision variable is a full mediating variable.The implication of the results of this study is that to increase Parental Satisfaction of Students

If the program is not ranked by BYU, a value higher than the highest BYU ranking is assigned to this variable RANKED A dichotomous variable that equals 1 if the faculty member has at

This is the rule, rather than the exception.”33 In Assam’s Dhubri town, 500 refugees, mostly children died due to acute sanitation problem in the camps.34 The cholera epidemic of the

17 of 17 ADDITIONAL RESPONSE SPACE FOR QUESTION 6 If you want this diagram to be marked, rule a single diagonal line through the diagram on page 8... lear zone — margin trimmed off

Thus, the adversity quotient in this study is a moderating variable, where achievement motivation will be higher if it is followed by a struggle to achieve the expected goals or

Score: 0 Accepted Answers: Type: Range 0.331,0.335 Based on the given data, answer the following up to question 18 is a continuous random variable uniformly distributed in then