Received: by 10.192.165.156 with SMTP id m28csp710129imm; Mon, 16 Apr 2018 07:31:11 -0700 (PDT) X-Google-Smtp-Source: AIpwx49ZLLEoiV7fJ3W8KolziSMu6JXtBosMfe/zBkGYDHdU5bdJZrQnIzuHGn3l0SSGSukpOLoa X-Received: by 10.99.185.8 with SMTP id z8mr6343744pge.436.1523889071331; Mon, 16 Apr 2018 07:31:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523889071; cv=none; d=google.com; s=arc-20160816; b=oot/rWYmsL4OWNYzPN2qGdjHfXsBEgextXqO6GHat8UiV/RNegju7xoLKKsBH4R+WM F7ZmeR6hkUa9nGQDEWdsLV3KSrJhqWYuqCgFufW0Emp3FEEDScmb/NJBktTfMHKlX3T5 v3c14ESDc46kXv40EOsh/T17Pc/dfChmpwQNd9f1GE+fSC7+cLsW8doK+935h16UmpHw mQWhsgaJhy3M0o/p1VHuoJR/AfKj0JxKftQMgitieG+13tD+cDrzM2mvvtafMD4Eyu2R /KIzqXuP/2RjiWEEO1kqKs/UTwXD1dTY85pZIa4w/GJ3i9PQxKetmSdUmJB0OAQdCMvs AfJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=d3n3EUggF45Kfzwtgm1Mvaolqlei1qM9lDlOHjGMW54=; b=UGl7iwW+bZJK8eUAKJ6ds6z10XSllBS8CXrZa4O2vtoptvsEPKwgsVnF2+/vV/3vRb OuJHDH+zn+35MspG8HzPWtsVetAL5gfcBukEZq/CAiNBcrcXQKxSLxXt94nZjbh0rvll Z0duvnxdz78nt3oihDr9e5IjKhVQnAXTLwTgpc7TRkY6tvTjp05Bk1i/WdL0EdF9Jsm6 Z4gT8YV8GTucjovoPWzCuCsHFJY+e7oF9ZJDXZ1MU3XswY2dD90tvVrVpTTgb+/bSTCL rbsMeWSR2qjvUMHjGdlcptiMciybTWK5l90iW35LD+U9eopU9dba6eqFsZHQ84T5lreq NCbg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p8si9676344pgn.406.2018.04.16.07.30.57; Mon, 16 Apr 2018 07:31:11 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754765AbeDPLg5 (ORCPT + 99 others); Mon, 16 Apr 2018 07:36:57 -0400 Received: from mx2.suse.de ([195.135.220.15]:36792 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754103AbeDPLgz (ORCPT ); Mon, 16 Apr 2018 07:36:55 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 9770FACCB; Mon, 16 Apr 2018 11:36:53 +0000 (UTC) From: Petr Mladek To: Jiri Kosina , Josh Poimboeuf , Miroslav Benes Cc: Joe Lawrence , Jessica Yu , Nicolai Stange , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, Petr Mladek Subject: [PATCH v3 0/2] livepatch: Allocate and free shadow variables more safely Date: Mon, 16 Apr 2018 13:36:45 +0200 Message-Id: <20180416113647.25288-1-pmladek@suse.com> X-Mailer: git-send-email 2.13.6 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Nikolai started to use shadow variables and found that list_head is not initialized correctly using the existing API. The problem is that LIST_HEAD_INIT() set pointers to itself. klp_shadow_alloc() then copies these pointers to another location. It would be possible to solve this by a late initialization. But this does not work well with klp_shadow_get_or_alloc(). Also this behavior is error prone. Note that list_head might be hidden in another structure, for example mutex. I suggest to change the API and allow to initialize the shadow variables using a custom callback. I think that we have already talked about this but we decided to go the easier way. It seems that it was a bad decision. I send also patch that add a symmetric callback to the klp_shadow_free() functions. It might be handy especially for klp_shadow_free_all(). Changes against v2: + Use pr_err() instead of WARN() when ctor() fails [Josh] + Some typos [Mirek] Changes against v1: + Rename init/free callbacks to ctor/dtor + Misc update of comments and commit messages + Fix sizeof() in the sample code in shadow-vars.txt Petr Mladek (2): livepatch: Initialize shadow variables safely by a custom callback livepatch: Allow to call a custom callback when freeing shadow variables Documentation/livepatch/shadow-vars.txt | 41 ++++++++---- include/linux/livepatch.h | 19 ++++-- kernel/livepatch/shadow.c | 108 ++++++++++++++++++++---------- samples/livepatch/livepatch-shadow-fix1.c | 43 +++++++++--- samples/livepatch/livepatch-shadow-fix2.c | 33 ++++----- 5 files changed, 163 insertions(+), 81 deletions(-) -- 2.13.6