Q:

Transferring an integer to device function does not work

For my cuda project I want to give my device function a single integer. 
My function looks like
__device__ void  PBKDF2_CUDA(const uint8_t password[], const int pass_len, const uint8_t Essid[], const int Essid_len, const int c, const int dkLen, uint32_t T_ptr[], int *PW_len_test)
{
    uint32_t Hash_ptr[5] = {0};
    uint32_t L[5]={0,0,0,0,0};
    uint32_t T[8] = {0};

    //Maybe working
    /*uint8_t * password_shrinked = (uint8_t*)malloc(8 + 1);
    for(int i = 0; i < 8; i++)
        password_shrinked[i] = password[i];
    password_shrinked[8 + 1] = 0;*/
    int password_len = pass_len;
    if (pass_len != 8)
    {
        *PW_len_test = pass_len;
        password_len = 8;
    }
    uint8_t * password_shrinked = (uint8_t*)malloc(sizeof(uint8_t)*(password_len + 1));
    for (int i = 0; i < password_len; i++)
        password_shrinked[i] = password[i];
    password_shrinked[password_len + 1] = 0;
    //Some other stuff
    free(password_shrinked);
};

and I'm calling it from a kernel like this:
__global__ void kernel(uint8_t Password_list[], const int *Password_len, uint8_t Essid[], int *Essid_len, int *rounds,int *dkLen, uint32_t T[], int pmk_size, int *PW_len_test)
{
    int idx= threadIdx.x + blockDim.x*blockIdx.x;
    printf("Password_len is: %d\n", Password_len);
    PBKDF2_CUDA(Password_list+idx*(8), 8, Essid, *Essid_len, *rounds, *dkLen, T+idx*pmk_size, PW_len_test + idx*sizeof(int));
}

Calling kernel in main function:
kernel<<<BLOCKS, THREADS>>>(Pass_d, Pass_len_d, Essid_d, Essid_len_d, rounds_d, key_len_d, PMK_d, PMK_size, PW_len_test_d);

Now, regardless if I set Pass_len_d to 8, or if I'm calling the kernel with 8 instead of Pass_len_d, my device function creates garbage (returning wrong values, explanation below). It only works if I set the value manually in the kernel function (as seen above) or in the device function.
With garbage I mean that some returned values are not calculated correctly from the password list (uint8_t array), but others are correctly calculated. Which words are correctly calculated changes with every run, so I assume there is a race condition somewhere, but I can not find it.

A:

There's at least one buffer overflow.
password_shrinked[password_len + 1] = 0; writes to a slot one byte above what was allocated.
Remember that if you allocate password_len + 1 bytes, the last location in the array is password_len. 

