Received: by 10.213.65.68 with SMTP id h4csp1196145imn; Wed, 14 Mar 2018 12:31:21 -0700 (PDT) X-Google-Smtp-Source: AG47ELuv/grevCkUp3NiESyiukS+1H5mpg1syKhhTaWDn16f+UuJKdldMRH2TOYQIU4rIKy20j0K X-Received: by 2002:a17:902:6ec5:: with SMTP id l5-v6mr5120310pln.113.1521055881538; Wed, 14 Mar 2018 12:31:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521055881; cv=none; d=google.com; s=arc-20160816; b=OV/2Gg67LVLIrfbLrQMhFifzpk9InrVjpkPwSgS63BH7kdWnSJy/jZ4NsbMGyVz+jh sqNx/inmBk/a/l6JvjjHfIVqpNLxNlHrVlRpQkp7pmuiHFVbmAiJ6y/L0wacgoj4ssOc RSKynfkmtouOoUgh/E+0qwiw/1lN3RacbE88B63SSp1pWhgFTwkPyJ4gj+EqZrju3LmC BZJzJhnY/u0gaHR2OwNOhvieLcvO8jryKM7556iN6lzJVHwXwi4u+BI2XDjKHJmbTrdc JGK6LlJGFp6AW2TrXBIw3fyCwXEvRHU41TxX1Bndx/VI38KpABCuJGaWSWWzX3yq8P4L kycA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=gI7VtfXoiBs/s695YVNLY+YFhCi6WFmzyM85AkOD7Tw=; b=hf8WWJQzyywG/ojzR59hWktLa80LGfuLQgcwPgzGNSvRDodfoVTCaIJbengD185CSD xAO3iVwcxONYqH4nMzO2uzxZgK8a64iwM9KvPhsMGGUdFdn3/LRQY+tSaXZWCkN5l7Dk V0eAlYxlltuRh+S9cWGzJne22grSfrYcZjsA8++wVhq0JIUpIXza1pKEjQCP1c0o+1jh RJFF1kBp9lny4pdJtFE0OzaPbIy0Xm9hI/y84l+8UiN64g8ke4GII7mpKX+KzYbK5Fo1 Gf+rSb9bPDPm3a0xH9Hyzsj0lSoAtuL8kUpjGLKvNhdv0sPl50SlpaL6OHfU3l3cQfrP A3jQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k5si2284921pgp.751.2018.03.14.12.31.06; Wed, 14 Mar 2018 12:31:21 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752081AbeCNT3D (ORCPT + 99 others); Wed, 14 Mar 2018 15:29:03 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44822 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751700AbeCNT3B (ORCPT ); Wed, 14 Mar 2018 15:29:01 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1EF8B40201A3; Wed, 14 Mar 2018 19:29:00 +0000 (UTC) Received: from treble (ovpn-122-218.rdu2.redhat.com [10.10.122.218]) by smtp.corp.redhat.com (Postfix) with SMTP id 5D0EF10AF9CE; Wed, 14 Mar 2018 19:28:57 +0000 (UTC) Date: Wed, 14 Mar 2018 14:28:57 -0500 From: Josh Poimboeuf To: Petr Mladek Cc: Jiri Kosina , Miroslav Benes , Joe Lawrence , Jessica Yu , Nicolai Stange , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] livepatch: Initialize shadow variables by init function safely Message-ID: <20180314192857.yfdk2uwn4okuzlfh@treble> References: <20180313155448.1998-1-pmladek@suse.com> <20180313155448.1998-2-pmladek@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20180313155448.1998-2-pmladek@suse.com> User-Agent: Mutt/1.6.0.1 (2016-04-01) X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 14 Mar 2018 19:29:00 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 14 Mar 2018 19:29:00 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jpoimboe@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 13, 2018 at 04:54:47PM +0100, Petr Mladek wrote: > The existing API allows to pass a sample data to initialize the shadow > data. It works well when the data are position independent. But it fails > miserably when we need to set a pointer to the shadow structure itself. > > Unfortunately, we might need to initialize the pointer surprisingly > often because of struct list_head. It is even worse because the list > might be hidden in other common structures, for example, struct mutex, > struct wait_queue_head. Can you provide a specific example in the changelog of where this was needed? > This patch makes the API more safe. A custom init function and data > are passed to klp_shadow_*alloc() functions instead of the sample data. > > Note that the init_data are not longer a template for the shadow->data. > It might point to any data that might be necessary when the init > function is called. > > In addition, the newly allocated shadow structure is initialized > only when it is really used. I don't understand this sentence. It makes it sound like the init function is called when you do klp_shadow_get(). However, looking at the code, the init function is always called after allocation. > For this, the init function must be > called under klp_shadow_lock. On one hand, this adds a risk of > ABBA deadlocks. On the other hand, it allows to do some operations > safely. For example, we could add the new structure into an > existing list. > diff --git a/include/linux/livepatch.h b/include/linux/livepatch.h > index 4754f01c1abb..fc7c64ce0992 100644 > --- a/include/linux/livepatch.h > +++ b/include/linux/livepatch.h > @@ -186,11 +186,20 @@ static inline bool klp_have_reliable_stack(void) > IS_ENABLED(CONFIG_HAVE_RELIABLE_STACKTRACE); > } > > +struct klp_shadow; Why is this forward struct declaration needed? > @@ -150,6 +145,23 @@ static void *__klp_shadow_get_or_alloc(void *obj, unsigned long id, void *data, > goto exists; > } > > + new_shadow->obj = obj; > + new_shadow->id = id; > + > + if (init_func) { > + int err; > + > + err = init_func(obj, new_shadow->data, init_data); Am I hallucinating, or will new_shadow->data always be NULL? How did it even work before? -- Josh