Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp605961ybl; Mon, 12 Aug 2019 23:14:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqzttdlk5sdbkAbMz9qIueBk9LIsetexWG6cj3UYzqdIDZWYHtvqnRBRJkZ3D9K4I9Y9NifE X-Received: by 2002:a17:902:441:: with SMTP id 59mr28283633ple.62.1565676867504; Mon, 12 Aug 2019 23:14:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565676867; cv=none; d=google.com; s=arc-20160816; b=w2F11aG9oNMwqwgqejTYVEIKJ5eqZkDt41LJ59RDcKsKbLihNLPx+/BjOD296YyluG +tZqBQhiNB54FK22SV2NvnMw0U6Nl9lQfsYm6ZVLnB3N+cCadXenI8RUA5FQ4aZUWK8Q DhlD2+I1lAoIQrXluNKS+CIOvhIOV1nx4CIdYVnLnNW5wJApPgKBnZMoq5kn4T/LVUM5 SK1GqgK0tp9gk1oZBBAdVxuZw1Zd/bT9Ft9nwtbagz+HNc67du53fNpFRQztVTf8OymO mIQTrN+07OyHPY2onWAS3PAo3kUDI0buuzzA2AgcRh5LeHdU8BRAVOncTcSpRw5yXe7d O63w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=Xgef0XFFFPz0RPMRvPeUpqgM+lNFsR5792wofX4MhfM=; b=m8lTxwXGYoHJvWw2Ie8QtN1cFksvyx3E1q7s8XxcYbcOVgR9vZMV2vbfiI0rZk/6A9 NZ4KsJEsGhf2+PTtG2HH+g1wZLtQdrjPiLfpuN8TiKetYrQeJoqjl4aHZd+nBREjOQKv 6js4dGXkf0c6SCy5HTfOllVMfRJJ2cKXyymgnbQ9CwI8SMI/21LDvKOYSGbmBh5gdQaT NyeUCzp9T0BJ0KZV0evaNpKne6BzKWot/gWhlfE69lBHMeGU3D+C2rSPLet0EoPC7g0B 7sanMqTVFwmIAM55EXvJRWmSirsGZnAzQxc0jZi9NI7LT3zT7UXyBLDyNqun4NEeyHOr Clsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2019-08-05 header.b=QTBRw1J8; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b="Q/qjpYmC"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q7si10744232pfn.113.2019.08.12.23.14.12; Mon, 12 Aug 2019 23:14:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2019-08-05 header.b=QTBRw1J8; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b="Q/qjpYmC"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727636AbfHMGLd (ORCPT + 99 others); Tue, 13 Aug 2019 02:11:33 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:37120 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727614AbfHMGLb (ORCPT ); Tue, 13 Aug 2019 02:11:31 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x7D68wnv022022; Tue, 13 Aug 2019 06:11:11 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2019-08-05; bh=Xgef0XFFFPz0RPMRvPeUpqgM+lNFsR5792wofX4MhfM=; b=QTBRw1J8EwzFKxTiUFmLQgNu5gJSIlHqxIXINo/GKFDy5+tNbI6IEjURZfo8AowNa2RE HRbAaqZ3IYt5aDtt8KrnQa56YdCAoa+U49qwVSN8n0bSTuFfvXX7Y4DsSvTCR5Cpk4/h QW8xlED9BzhsCmcmoD4sny1+qHo8meLw4/wvHZvHdZ5fdwneMqAJ6ZjLSQ2GcWJCnpKz Bs1ZQOHbykMMpo+/94Mrav4hM7xrrhKy8Oqgloat9Bc3tGiTHL2WrqaqV93a61puONki 3C6OFymR8D7IcthR2aE/6Sb7TZAzwTm7hgQAPry4VsOOY3jZ4UfCCITlQwgzJjtA0ZzW ow== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2018-07-02; bh=Xgef0XFFFPz0RPMRvPeUpqgM+lNFsR5792wofX4MhfM=; b=Q/qjpYmChiHk6d3bxVVA9c4vw6ca/+dFQ+6gPMWpmbcZWJ5JmZhA1UWn0q+h3la2ajSX 6PiUwAACJVI0nHX4sH2xeyFtNHhRz3o+j5R2TM5sfGE7zXMtf6z+59Q6rXYzu3JyWXfC tYG//zJAueUGNN0T3aQW6eZ+8a9lqxx8MV3lM68DYYiSDuJ57UbDBAcy8xSJo/OMbLRI fPclPxgYrktrriyOddNXcJ375J3loPtH73vPBgHPiRGZ5HHbBPuhbKmLWtbcNJe4ZtM5 F+GJDpeoORDqdBjgmRiFWoqAzL8okVGvjn4CYJxDiy1AY+0oNVDk/Xt8+idc5jFlV54M zw== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 2u9pjqbvd2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Aug 2019 06:11:11 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x7D67Q1i096475; Tue, 13 Aug 2019 06:11:10 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3030.oracle.com with ESMTP id 2u9m0aydn9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Aug 2019 06:11:10 +0000 Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x7D6B9SB026468; Tue, 13 Aug 2019 06:11:09 GMT Received: from abi.no.oracle.com (/10.172.144.123) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 12 Aug 2019 23:11:09 -0700 From: Knut Omang To: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org, Shuah Khan , Jonathan Corbet , Masahiro Yamada , Michal Marek , Greg Kroah-Hartman , Shreyans Devendra Doshi <0xinfosect0r@gmail.com>, Alan Maguire , Brendan Higgins , Kevin Hilman , Hidenori Yamaji , Frank Rowand , Timothy Bird , Luis Chamberlain , "Theodore Ts'o" , Daniel Vetter , Stephen Boyd , Knut Omang Subject: [RFC 05/19] ktf: Implementation of ktf support for overriding function entry and return. Date: Tue, 13 Aug 2019 08:09:20 +0200 Message-Id: <1fccfe3062ba6c7a2c8171df8e41975e28dae9ec.1565676440.git-series.knut.omang@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9347 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1908130067 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9347 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1908130067 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alan Maguire This is a very powerful and yet simple way to verify or modify behaviour of kernel calls. It uses the same technique as the error injection framework in kernel/fail_function.c to to override function entry and return. In addition to error injection, this is very useful to for instance verify that a particular API actually ends up being called, and in the right way, as an effect of a test. ktf_override.c: support for overriding function entry. ktf_override.h: Function override support interface for KTF. Signed-off-by: Alan Maguire Signed-off-by: Knut Omang --- tools/testing/selftests/ktf/kernel/ktf_override.c | 45 ++++++++++++++++- tools/testing/selftests/ktf/kernel/ktf_override.h | 15 +++++- 2 files changed, 60 insertions(+) create mode 100644 tools/testing/selftests/ktf/kernel/ktf_override.c create mode 100644 tools/testing/selftests/ktf/kernel/ktf_override.h diff --git a/tools/testing/selftests/ktf/kernel/ktf_override.c b/tools/testing/selftests/ktf/kernel/ktf_override.c new file mode 100644 index 0000000..7f046c8 --- /dev/null +++ b/tools/testing/selftests/ktf/kernel/ktf_override.c @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Author: Alan Maguire + * + * SPDX-License-Identifier: GPL-2.0 + * + * ktf_override.c: support for overriding function entry. + */ +#include +#include +#include "ktf.h" +#include "ktf_override.h" + +asmlinkage void ktf_just_return_func(void); + +asm( + ".type ktf_just_return_func, @function\n" + ".globl ktf_just_return_func\n" + "ktf_just_return_func:\n" + " ret\n" + ".size ktf_just_return_func, .-ktf_just_return_func\n" +); + +void ktf_post_handler(struct kprobe *kp, struct pt_regs *regs, + unsigned long flags) +{ + /* + * A dummy post handler is required to prohibit optimizing, because + * jump optimization does not support execution path overriding. + */ +} +EXPORT_SYMBOL(ktf_post_handler); + +void ktf_override_function_with_return(struct pt_regs *regs) +{ + KTF_SET_INSTRUCTION_POINTER(regs, (unsigned long)&ktf_just_return_func); +} +EXPORT_SYMBOL(ktf_override_function_with_return); +NOKPROBE_SYMBOL(ktf_override_function_with_return); + +int ktf_register_override(struct kprobe *kp) +{ + return register_kprobe(kp); +} +EXPORT_SYMBOL(ktf_register_override); diff --git a/tools/testing/selftests/ktf/kernel/ktf_override.h b/tools/testing/selftests/ktf/kernel/ktf_override.h new file mode 100644 index 0000000..8a9cf39 --- /dev/null +++ b/tools/testing/selftests/ktf/kernel/ktf_override.h @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Author: Alan Maguire + * + * SPDX-License-Identifier: GPL-2.0 + * + * ktf_override.h: Function override support interface for KTF. + */ +#include +#include "ktf.h" + +void ktf_post_handler(struct kprobe *kp, struct pt_regs *regs, + unsigned long flags); +void ktf_override_function_with_return(struct pt_regs *regs); +int ktf_register_override(struct kprobe *kp); -- git-series 0.9.1