Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 
0003 #include <errno.h>
0004 #include <fcntl.h>
0005 #include <signal.h>
0006 #include <stdio.h>
0007 #include <string.h>
0008 #include <sys/ioctl.h>
0009 #include <sys/mman.h>
0010 #include <sys/stat.h>
0011 #include <sys/types.h>
0012 #include <unistd.h>
0013 
0014 #include "vas-api.h"
0015 #include "utils.h"
0016 
0017 static bool faulted;
0018 
0019 static void sigbus_handler(int n, siginfo_t *info, void *ctxt_v)
0020 {
0021     ucontext_t *ctxt = (ucontext_t *)ctxt_v;
0022     struct pt_regs *regs = ctxt->uc_mcontext.regs;
0023 
0024     faulted = true;
0025     regs->nip += 4;
0026 }
0027 
0028 static int test_ra_error(void)
0029 {
0030     struct vas_tx_win_open_attr attr;
0031     int fd, *paste_addr;
0032     char *devname = "/dev/crypto/nx-gzip";
0033     struct sigaction act = {
0034         .sa_sigaction = sigbus_handler,
0035         .sa_flags = SA_SIGINFO,
0036     };
0037 
0038     memset(&attr, 0, sizeof(attr));
0039     attr.version = 1;
0040     attr.vas_id = 0;
0041 
0042     SKIP_IF(access(devname, F_OK));
0043 
0044     fd = open(devname, O_RDWR);
0045     FAIL_IF(fd < 0);
0046     FAIL_IF(ioctl(fd, VAS_TX_WIN_OPEN, &attr) < 0);
0047     FAIL_IF(sigaction(SIGBUS, &act, NULL) != 0);
0048 
0049     paste_addr = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0ULL);
0050 
0051     /* The following assignment triggers exception */
0052     mb();
0053     *paste_addr = 1;
0054     mb();
0055 
0056     FAIL_IF(!faulted);
0057 
0058     return 0;
0059 }
0060 
0061 int main(void)
0062 {
0063     return test_harness(test_ra_error, "inject-ra-err");
0064 }
0065