Navigation

    全志在线开发者论坛

    • Register
    • Login
    • Search
    • Categories
    • Tags
    • 在线文档
    • 社区主页

    cryptoengine TRNG模块内存泄露

    其它全志芯片讨论区
    1
    2
    1315
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      mengxp LV 5 last edited by

      写了个afalg测试 TRNG 接口,发现有内存泄露,肉眼可见的内存泄露。应该是发生在内核层面的。

      我的芯片是 R328-S3,Tina 3.5 SDK
      测试代码如下,原厂大神来看看吧。

      运行前free一下,然后等跑了几千轮几万轮后再free一下,少了很多MB内存。
      用top看一下,发现测试程序没有占用多少内存,所以基本可以石锤是内核层面内存泄露。

      我这边也慢慢分析下 sunxi-ss 模块哪里有泄露。

      #include <errno.h>
      #include <stdint.h>
      #include <sys/uio.h>
      #include <sys/syscall.h>
      #include <sys/socket.h>
      #include <linux/if_alg.h>
      #include <stddef.h>
      #include <stdio.h>
      #include <stdlib.h>
      #include <string.h>
      #include <unistd.h>
      
      #ifndef SOL_ALG
      #define SOL_ALG 279
      #endif
      
      int os_get_random(unsigned char *buf, size_t len)
      {
          int trng_tfmfd = 0;
          int trng_opfd = 0;
          int retval = -1;
      
          do {
              struct sockaddr_alg sa = {
                .salg_family = AF_ALG,
                .salg_type = "rng",
                .salg_name = "trng"
              };
              int ret;
      
              trng_tfmfd = socket(AF_ALG, SOCK_SEQPACKET, 0);
              if (trng_tfmfd < 0)
              {
                  printf("socket failed\n");
                  break;
              }
      
              ret = bind(trng_tfmfd, (struct sockaddr *)&sa, sizeof(sa));
              if (ret)
              {
                  printf("bind failed\n");
                  break;
              }
      
              trng_opfd = accept(trng_tfmfd, NULL, 0);
              if (trng_opfd < 0)
              {
                  printf("accept failed\n");
                  break;
              }
      
              retval = 0;
              while (len > 0)
              {
                  ret = read(trng_opfd, buf, len);
                  if (ret < 0)
                  {
                      retval = -1;
                      break;
                  }
                  buf += ret;
                  len -= ret;
              }
      
          } while (0);
      
          if (trng_opfd > 0)
              close(trng_opfd);
      
          if (trng_tfmfd > 0)
              close(trng_tfmfd);
      
          return retval;
      }
      
      #if 1
      unsigned char trng_buf[65536];
      
      void Test_TRNG(void)
      {
          int i = 0;
      
          while(1)
          {
              os_get_random(trng_buf, 512);
      
              if(!(i++ % 1000))
                  printf("random %d\n", i);
          }
      }
      
      int main(void)
      {
          Test_TRNG();
          return 0;
      }
      #endif
      
      
      M 1 Reply Last reply Reply Quote Share 0
      • M
        mengxp LV 5 @mengxp last edited by mengxp

        @mengxp 看了下r328上使用的v3代码,关键字alloc,我发现有

        ss_rng_start buf 内存泄露 (kmalloc without kfree)

        目前就发现这一个

        1 Reply Last reply Reply Quote Share 0
        • 1 / 1
        • First post
          Last post

        Copyright © 2024 深圳全志在线有限公司 粤ICP备2021084185号 粤公网安备44030502007680号

        行为准则 | 用户协议 | 隐私权政策