From owner-freebsd-hackers@FreeBSD.ORG Thu Apr 8 14:17:48 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 29456106564A for ; Thu, 8 Apr 2010 14:17:48 +0000 (UTC) (envelope-from mahan@mahan.org) Received: from ns.mahan.org (ns.mahan.org [67.116.10.138]) by mx1.freebsd.org (Postfix) with ESMTP id 087628FC0A for ; Thu, 8 Apr 2010 14:17:46 +0000 (UTC) Received: from Gypsy.mahan.org (crowTrobot [67.116.10.140]) by ns.mahan.org (8.13.6/8.13.6) with ESMTP id o38EMAAq083108 for ; Thu, 8 Apr 2010 07:22:10 -0700 (PDT) (envelope-from mahan@mahan.org) Message-ID: <4BBDE58A.9050502@mahan.org> Date: Thu, 08 Apr 2010 07:17:46 -0700 From: Patrick Mahan User-Agent: Thunderbird 2.0.0.22 (X11/20090605) MIME-Version: 1.0 To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Modifying ELF files X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Apr 2010 14:17:48 -0000 In my job, we are producing applications and KLM's for our product that require them to be signed so that our installer will recognize and validate our images. The signature is stored in each app as unsigned char signature[40] __attribute__((section(".compsign"))); What I need to do is open the file for writing, locate the ".compsign" section and stuff in the signature, write it out and close the file. (simple ELF manipulation) An 'ls -l' shows the following: % ls compklm.ko -rw-r--r-- 1 pmahan pmahan 125296 Apr 6 22:50 /home/pmahan/temp/compklm.ko When I try to run my program ./signfile --signature=A203239897C8EB360D1EB2C84E8E77B16E5B7C9A compklm.ko open: Text file busy Googling and looking at the kernel sources, it seems that it detects this file contains 'shared text', that is, it is an executable file and does not allow me to open it for writing. I understand (from my google search) this is a means to keep you from shooting yourself in the foot. But there has got to be a way and I really don't want to grovel through the compiler code to find it. I looked at using libelf.so but it also requires that the file be open for writing. So I am kinda of stuck. If I cannot find a quick solution we might need to do all of our signing on our FC11 box which does not have this issue. Thanks for the education I always get from this list, Patrick