From patchwork Mon Jul 28 12:20:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 34351 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f72.google.com (mail-oa0-f72.google.com [209.85.219.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A18F3213FD for ; Mon, 28 Jul 2014 12:30:52 +0000 (UTC) Received: by mail-oa0-f72.google.com with SMTP id m1sf51197630oag.7 for ; Mon, 28 Jul 2014 05:30:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :mime-version:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe:content-type; bh=/6FUNosJWVgzF4sFJHOUI/SjTKv+qcXg4etXgny3640=; b=fNSNaMAAsi0sCrVdTE+LV/6yiDcR47n8zWNCepWvVsU7dfQYY+F6zNZpOqcrp/8wMS V1UgGeHfe5DO6SfYKNSCAJQIbScHXMNhQxf5gURPMXOCHCvGAuHmefJ5Py45psWwcn5p x3j6bMGQtIe19TkpFyvh6dJQLYj+aTvCnpuP4SwgCDrZafp/EDU/gf80FQRSXfShISce Zthx5ykgRgQnLNejdN9h7ryA/BjzFBrVBHGYbQoHKdFI0DhqUA2sw7cWk828ISM/dqqx 7w2vCmd4f6m9/umohTFhJf9YtusFSrxyUrKMHO554fSrVTW7CXXh4yg3eSZZv+2sLaKu bcTw== X-Gm-Message-State: ALoCoQldeLIAsTuOGFfGR1PSKeeODz28sDjGmRIu4mJAlghUzzR8wMBkzsxlsOXdCrbSCyr9/1ut X-Received: by 10.182.4.73 with SMTP id i9mr7322275obi.28.1406550652240; Mon, 28 Jul 2014 05:30:52 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.29.55 with SMTP id a52ls2027697qga.14.gmail; Mon, 28 Jul 2014 05:30:52 -0700 (PDT) X-Received: by 10.52.0.209 with SMTP id 17mr4693075vdg.60.1406550652125; Mon, 28 Jul 2014 05:30:52 -0700 (PDT) Received: from mail-vc0-f169.google.com (mail-vc0-f169.google.com [209.85.220.169]) by mx.google.com with ESMTPS id d8si12258066vee.90.2014.07.28.05.30.52 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 28 Jul 2014 05:30:52 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.169 as permitted sender) client-ip=209.85.220.169; Received: by mail-vc0-f169.google.com with SMTP id le20so2217720vcb.28 for ; Mon, 28 Jul 2014 05:30:52 -0700 (PDT) X-Received: by 10.52.37.81 with SMTP id w17mr713667vdj.95.1406550652035; Mon, 28 Jul 2014 05:30:52 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp162555vcb; Mon, 28 Jul 2014 05:30:51 -0700 (PDT) X-Received: by 10.68.230.166 with SMTP id sz6mr38162246pbc.32.1406550651244; Mon, 28 Jul 2014 05:30:51 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ib1si17648440pbb.227.2014.07.28.05.30.50 for ; Mon, 28 Jul 2014 05:30:51 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752794AbaG1Mat (ORCPT + 23 others); Mon, 28 Jul 2014 08:30:49 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:4603 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751664AbaG1Maq (ORCPT ); Mon, 28 Jul 2014 08:30:46 -0400 Received: from 172.24.2.119 (EHLO lggeml416-hub.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id BXG31223; Mon, 28 Jul 2014 20:30:38 +0800 (CST) Received: from kernel-host.huawei (10.107.197.247) by lggeml416-hub.china.huawei.com (10.72.61.111) with Microsoft SMTP Server id 14.3.158.1; Mon, 28 Jul 2014 20:30:30 +0800 From: Wang Nan To: Masami Hiramatsu , Ingo Molnar , Thomas Gleixner , Andi Kleen , Pei Feiyue CC: , , Subject: [PATCH] kprobes/x86: opt: free optinsn cache when range check fails Date: Mon, 28 Jul 2014 20:20:19 +0800 Message-ID: <1406550019-70935-1-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.4 MIME-Version: 1.0 X-Originating-IP: [10.107.197.247] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: wangnan0@huawei.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.169 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This patch frees optinsn slot when range check error to prevent memory leaks. Before this patch, cache entry in kprobe_insn_cache won't be freed if kprobe optimizing fails due to range check failure. Signed-off-by: Wang Nan Acked-by: Masami Hiramatsu --- arch/x86/kernel/kprobes/opt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c index f304773..f1314d0 100644 --- a/arch/x86/kernel/kprobes/opt.c +++ b/arch/x86/kernel/kprobes/opt.c @@ -338,8 +338,10 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op) * a relative jump. */ rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE; - if (abs(rel) > 0x7fffffff) + if (abs(rel) > 0x7fffffff) { + __arch_remove_optimized_kprobe(op, 0); return -ERANGE; + } buf = (u8 *)op->optinsn.insn;