Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2245814imu; Wed, 21 Nov 2018 08:42:37 -0800 (PST) X-Google-Smtp-Source: AJdET5e7dsWFkbM3d+/0jbs3V8G5G4lkmQ6SRIJd8Jx75eoGbU4TNysErDzVnVWHK5P3gLyez0Zo X-Received: by 2002:a62:1095:: with SMTP id 21-v6mr7418528pfq.227.1542818557659; Wed, 21 Nov 2018 08:42:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542818557; cv=none; d=google.com; s=arc-20160816; b=GCJNJdfosKUNE4UP3OavxMXxgY66Ohh1GZuazAj/a9WYOlK/BgPeUdZXwVflQ/307H Iqc1AHgxZFIRHHrjqmbwwOY8Y5C8n9iU6Iy3Mtn+w0nvWA5x02/YpK4jRtR/qvOCPl8E 0sZmznu251VxzaVK7Kn+88wRuf0ZZY1bsWW8h+B+nXmNY4D0Tmzp3QCDjCw3rwGrli1+ vmHh3htYvZs8KS1YN6Uqk7dYP0qT1zXfw0pyJ5XAyh1xhgqsCp9z3VY3xOwQYpz+Z25h QvSAMiLwbOWfEe1GZ7sNgxlXwYIBziUPZLYjlCjJtWm6kDFqPeQ04z6sIHyPAFyRzzPk j3AA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=Ck19Du9S+69/L7+DjYKCJobeqrZECFzl++gPC270HtU=; b=ZN2RIEPLy/F72KBotUU1D2rc1qQb85il1oVcwj6zY2sZPPKJRiSoAbPWb8BUANwBBU zl4G6gh09wXdaLEJyPiXolyEhKRkdwDJ+vX2hU0gwkIBbi9vAIzGQtwyIOl0FCAVaUT7 dfepNwWJRsYqBEAOmC169vKnmmKLL7e4vIOqEAplByG37cBZ1zg736YH6oskymT1cY2g 6VQN19tbcsm7vW/jRMgNwiwcFcBVJGx8m0pDMlDJXq25vyf2Yj88eHt1HV/3bnFVs4e/ WLlmLniHJAOq2VVmwyLFE+WajiQYib7M5N7Iy5rohG7kzNKacWuEaveUTXSkDTYDRwJX SQGg== 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 k11si30544968pgg.430.2018.11.21.08.42.01; Wed, 21 Nov 2018 08:42:37 -0800 (PST) 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 S1730763AbeKVAeD (ORCPT + 99 others); Wed, 21 Nov 2018 19:34:03 -0500 Received: from mx2.suse.de ([195.135.220.15]:36924 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729157AbeKVAeD (ORCPT ); Wed, 21 Nov 2018 19:34:03 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 3CA8AAC55; Wed, 21 Nov 2018 13:59:30 +0000 (UTC) Date: Wed, 21 Nov 2018 14:59:29 +0100 (CET) From: Miroslav Benes To: Petr Mladek cc: Jiri Kosina , Josh Poimboeuf , Jason Baron , Joe Lawrence , Evgenii Shatokhin , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, Jessica Yu Subject: Re: [PATCH v13 04/12] livepatch: Consolidate klp_free functions In-Reply-To: <20181015123713.25868-5-pmladek@suse.com> Message-ID: References: <20181015123713.25868-1-pmladek@suse.com> <20181015123713.25868-5-pmladek@suse.com> User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > -/* > - * Free all functions' kobjects in the array up to some limit. When limit is > - * NULL, all kobjects are freed. > - */ > -static void klp_free_funcs_limited(struct klp_object *obj, > - struct klp_func *limit) > +static void klp_free_funcs(struct klp_object *obj) > { > struct klp_func *func; > > - for (func = obj->funcs; func->old_name && func != limit; func++) > - kobject_put(&func->kobj); > + klp_for_each_func(obj, func) { > + /* Might be called from klp_init_patch() error path. */ > + if (func->kobj.state_initialized) > + kobject_put(&func->kobj); > + } > } I have not noticed till today, but state_initialized is probably not the best idea. kobject_init_and_add() sets it to 1 in kobject_init() part but then _add() is called which could result in error. So we would end up with state_initialized equal to 1 and kobject reference equal to 0. Later call to kobject_put() in klp_free_funcs() (or elsewhere) would not call ->release method, because refcount would be 0 by then. I think that all would end up well, but that does not mean we should not fix it. We could use state_in_sysfs, but I do not think it guarantees anything. Both are internal states and maybe we should not rely on them. So kref_read() and check the reference? Miroslav