We continue discussing the paper "Shielding applications from an untrusted cloud with Haven,” written by Andrew Baumann, Marcus Peinado, and Galen Hunt. We were describing how the paper assumes a malicious cloud provider which is a convenient proxy for all real threats. And how it utilizes the hardware isolation provided by Intel SGX to form an enclave and utilizes attestation. This hardware isolation involved new instructions to establish, protect and a gate to be called to enter.A portion of physical memory was encrypted and integrity protected. We now cite some of the attack vectors that influenced the design. The first is lago attacks. This is one where a malicious kernel with a carefully chosen sequence of integer return values to system calls can lead a supposedly protected process to act against its interest. For example, malloc() returns pointers to user's stack and read() fails with EROFs in a competing system. This paper suggest not to check all the system calls but to admit OS into the trusted computing base and using a drawbridge ABI ( a selection of few runtime calls) for a shield module within the enclave to communicate with the runtime. The untrusted interface is between the shield module and the untrusted runtime and there is a policy mechanism enforced by approximately twenty calls with restricted semantics. The policy in the guest is a virtual resource policy affecting virtual address allocation and threads while the policy in the host is a physical resource policy affecting physical pages, VCPUs. The shield module uses a reserved area of protected memory and file system and does a sanity check of untrusted inputs
#codingexercise
To the exercise described earlier using an N*N matrix of 0 and 1, perform an anticlockwise rotation and gravitation pull on the matrix.
#codingexercise
To the exercise described earlier using an N*N matrix of 0 and 1, perform an anticlockwise rotation and gravitation pull on the matrix.
Start Rotate Pull
0000 0000 0000
0000 0011 0001
0110 0011 0011
1110 0001 0011
int[,] RotateAndDrop(int[, ] matrix, int N)
{
var newMatrix = new int[N,N];
for (int p = N-1; p >=0; p--)
for (int q= N-1; q >= 0; q--)
newMatrix[N-q-1, p] = Matrix[p,q];
for (int j = 0; j < N; j++)
for (int i = N-1; i >= 0; i--)
if (newMatrix[i,j] == 0 && i-1 >=0){
newMatrix[i,j] = newMatrix[i-1,j];
newMatrix [i-1,j] =0;
}
return newMatrix;
}
Check whether the final position of the board has four elements in a row either horizontally, vertically or diagonally
bool BoardHasFourInRow(int[,] matrix, int N)
{
for (int i =0; i<N; i++)
for (int j = 0; j<N; j++)
if (FourInRow(matrix, N, i,j) == true) return true;
return false;
}
Bool FourInRow( int [,] matrix, int N, int i, intj)
{
// horizontal count
Int h = 0;
Int x = i;
While (x>0 && matrix [x,j] == matrix[i,j]) {h++;x--;}
x = i+1;
While (x < N && matrix [x, j] == matrix [i, j]) {h++; x++;}
If h >=4 return true;
//vertical count
Int v = 0;
Int y = j;
While (y>0 && matrix [i,y] == matrix[i,j]) {v++;y--;}
y= j+1;
While (y < N && matrix [i, y] == matrix [i, j]) {v++; y++;}
If v>=4 return true;
// diagonal forward
int d = 0;
x = i;
y = j;
While (x> 0 && y>0 && matrix [x,y] == matrix[i,j]) {d++;y--;x--;}
y= j+1;x=i+1;
While (x < N && y < N && matrix [x, y] == matrix [i, j]) {d++; y++;x++;}
If d>=4 return true;
// diagonal backward
}
int[,] RotateAndDrop(int[, ] matrix, int N)
{
var newMatrix = new int[N,N];
for (int p = N-1; p >=0; p--)
for (int q= N-1; q >= 0; q--)
newMatrix[N-q-1, p] = Matrix[p,q];
for (int j = 0; j < N; j++)
for (int i = N-1; i >= 0; i--)
if (newMatrix[i,j] == 0 && i-1 >=0){
newMatrix[i,j] = newMatrix[i-1,j];
newMatrix [i-1,j] =0;
}
return newMatrix;
}
Check whether the final position of the board has four elements in a row either horizontally, vertically or diagonally
bool BoardHasFourInRow(int[,] matrix, int N)
{
for (int i =0; i<N; i++)
for (int j = 0; j<N; j++)
if (FourInRow(matrix, N, i,j) == true) return true;
return false;
}
Bool FourInRow( int [,] matrix, int N, int i, intj)
{
// horizontal count
Int h = 0;
Int x = i;
While (x>0 && matrix [x,j] == matrix[i,j]) {h++;x--;}
x = i+1;
While (x < N && matrix [x, j] == matrix [i, j]) {h++; x++;}
If h >=4 return true;
//vertical count
Int v = 0;
Int y = j;
While (y>0 && matrix [i,y] == matrix[i,j]) {v++;y--;}
y= j+1;
While (y < N && matrix [i, y] == matrix [i, j]) {v++; y++;}
If v>=4 return true;
// diagonal forward
int d = 0;
x = i;
y = j;
While (x> 0 && y>0 && matrix [x,y] == matrix[i,j]) {d++;y--;x--;}
y= j+1;x=i+1;
While (x < N && y < N && matrix [x, y] == matrix [i, j]) {d++; y++;x++;}
If d>=4 return true;
// diagonal backward
d=0;
x=i;
y=j;
While (x> 0 && y<N && matrix [x,y] == matrix[i,j]) {d++;y++;x--;}
y= j-1;x=i+1;
While (x < N && y > 0 && matrix [x, y] == matrix [i, j]) {d++; y--;x++;}
If d>=4 return true;
return false;y= j-1;x=i+1;
While (x < N && y > 0 && matrix [x, y] == matrix [i, j]) {d++; y--;x++;}
If d>=4 return true;
}
No comments:
Post a Comment