【tcache stash unlink +】图解

8 篇文章 0 订阅

tcache stashing unlink +

  1. tcache 的入链操作

    在这里插入图片描述

  2. smallbin 入链操作

    在这里插入图片描述

  3. tcache stash

    • 源码

      #if USE_TCACHE
            /* While we're here, if we see other chunks of the same size,
               stash them in the tcache.  */
            size_t tc_idx = csize2tidx (nb);
            if (tcache && tc_idx < mp_.tcache_bins)
              {
                mchunkptr tc_victim;
                /* While bin not empty and tcache not full, copy chunks over.  */
                while (tcache->counts[tc_idx] < mp_.tcache_count
                   && (tc_victim = last (bin)) != bin) //注意这个结束条件
              {
                if (tc_victim != 0)
                  {
                    bck = tc_victim->bk; //这里victim的bk被我们修改了,bck为我们修改的值 &victim — 0x10
                    set_inuse_bit_at_offset (tc_victim, nb);
                    if (av != &main_arena)
                  set_non_main_arena (tc_victim);
                    bin->bk = bck;//victim 成为small bin的尾节点
                    bck->fd = bin;//victim的fd被设置为small bin
                  //这里需要注意的是victim + 0x8需要提前设置,作为victim的bk
                    tcache_put (tc_victim, tc_idx);
                      }
              }
      
    • 实际操作

      • 第一次stash,虚线是small bin 解链,绿色是未被攻击的情况, 红色是攻击的情况

        在这里插入图片描述

      • 第二次stash,就会将victim链入tcache,此时malloc就会申请到fake chunk

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值