From owner-svn-soc-all@FreeBSD.ORG Thu Jul 17 09:48:36 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id E3F16288 for ; Thu, 17 Jul 2014 09:48:35 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id CDE332378 for ; Thu, 17 Jul 2014 09:48:35 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6H9mZg1009405 for ; Thu, 17 Jul 2014 09:48:35 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s6H9mYes009387 for svn-soc-all@FreeBSD.org; Thu, 17 Jul 2014 09:48:34 GMT (envelope-from dpl@FreeBSD.org) Date: Thu, 17 Jul 2014 09:48:34 GMT Message-Id: <201407170948.s6H9mYes009387@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271013 - in soc2014/dpl/netmap-ipfwjit: . sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Jul 2014 09:48:36 -0000 Author: dpl Date: Thu Jul 17 09:48:34 2014 New Revision: 271013 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271013 Log: Modified Makefiles so that we can make everything now. Also added the most basic boilerplate to use llvm. Added: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.cc Deleted: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.c soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.bc Modified: soc2014/dpl/netmap-ipfwjit/Makefile soc2014/dpl/netmap-ipfwjit/Makefile.kipfw Modified: soc2014/dpl/netmap-ipfwjit/Makefile ============================================================================== --- soc2014/dpl/netmap-ipfwjit/Makefile Thu Jul 17 07:12:12 2014 (r271012) +++ soc2014/dpl/netmap-ipfwjit/Makefile Thu Jul 17 09:48:34 2014 (r271013) @@ -26,6 +26,7 @@ clean: -@rm -rf $(OBJDIR) kipfw @(cd ipfw && $(MAKE) clean ) + @rm ./ip_fw_rules.bc tgz: @$(MAKE) clean Modified: soc2014/dpl/netmap-ipfwjit/Makefile.kipfw ============================================================================== --- soc2014/dpl/netmap-ipfwjit/Makefile.kipfw Thu Jul 17 07:12:12 2014 (r271012) +++ soc2014/dpl/netmap-ipfwjit/Makefile.kipfw Thu Jul 17 09:48:34 2014 (r271013) @@ -124,7 +124,6 @@ #EFILES += sys/proc.h sys/rwlock.h sys/socket.h sys/socketvar.h #EFILES += sys/sysctl.h sys/time.h sys/ucred.h - #EFILES += vm/uma_int.h vm/vm_int.h vm/uma_dbg.h #EFILES += vm/vm_dbg.h vm/vm_page.h vm/vm.h #EFILES += sys/rwlock.h sys/sysctl.h @@ -136,6 +135,10 @@ # and the ": = " substitution packs spaces into one. EFILES = $(foreach i,$(EDIRS),$(subst $(empty) , $(i)/, $(EFILES_$(i): = ))) +BCFLAGS=-emit-llvm -c +CXX=clang++ +CXXFLAGS= $(CFLAGS) `llvm-config-devel --cxxflags --libs jit support` + include_e: -@echo "Building $(OBJPATH)/include_e ..." -$(HIDE) rm -rf $(OBJPATH)/include_e opt_* @@ -152,10 +155,18 @@ # session.o: CFLAGS = -O2 nm_util.o: CFLAGS = -O2 -Wall -Werror $(NETMAP_FLAGS) -$(MOD): $(IPFW_OBJS) +$(MOD): $(IPFW_OBJS) ../ip_fw_rules.bc $(MSG) " LD $@" $(HIDE)$(CC) -o $@ $^ $(LIBS) +#Generate the actual bytecode to be used +../ip_fw_rules.bc: + @$(CC) $(CFLAGS) $(BCFLAGS) -o ../ip_fw_rules.bc ../sys/netpfil/ipfw/ip_fw_rules.h + +ip_fw2.o: ip_fw2.cc + @echo "Building ip_fw2.cc" + clang++ $(CXXFLAGS) ../sys/netpfil/ipfw/ip_fw2.cc -o ./ip_fw2.o + clean: -rm -f *.o $(DN) $(MOD) -rm -rf include_e Added: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.cc ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.cc Thu Jul 17 09:48:34 2014 (r271013) @@ -0,0 +1,1543 @@ +/*- + * Copyright (c) 2002-2009 Luigi Rizzo, Universita` di Pisa + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: head/sys/netpfil/ipfw/ip_fw2.c 243711 2012-11-30 19:36:55Z melifaro $"); + +/* + * The FreeBSD IP packet firewall, main file + */ + +#include "opt_ipfw.h" +#include "opt_ipdivert.h" +#include "opt_inet.h" +#ifndef INET +#error "IPFIREWALL requires INET" +#endif /* INET */ +#include "opt_inet6.h" +#include "opt_ipsec.h" +#include "ip_fw_rules.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /* for ETHERTYPE_IP */ +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#ifdef INET6 +#include +#include +#include +#endif + +#include + +#include /* XXX for in_cksum */ + +#ifdef MAC +#include +#endif + +/* + * static variables followed by global ones. + * All ipfw global variables are here. + */ + +/* ipfw_vnet_ready controls when we are open for business */ +static VNET_DEFINE(int, ipfw_vnet_ready) = 0; +#define V_ipfw_vnet_ready VNET(ipfw_vnet_ready) + +static VNET_DEFINE(int, fw_deny_unknown_exthdrs); +#define V_fw_deny_unknown_exthdrs VNET(fw_deny_unknown_exthdrs) + +static VNET_DEFINE(int, fw_permit_single_frag6) = 1; +#define V_fw_permit_single_frag6 VNET(fw_permit_single_frag6) + +#ifdef IPFIREWALL_DEFAULT_TO_ACCEPT +static int default_to_accept = 1; +#else +static int default_to_accept; +#endif + +VNET_DEFINE(int, autoinc_step); +VNET_DEFINE(int, fw_one_pass) = 1; + +VNET_DEFINE(unsigned int, fw_tables_max); +/* Use 128 tables by default */ +static unsigned int default_fw_tables = IPFW_TABLES_DEFAULT; + +/* Rule functions, ordered by appereance in the code */ +static inline void rule_nop(int *); +static inline void rule_forward_mac(int); +static inline void rule_jail(int *, u_short, uint8_t, ipfw_insn *, struct ip_fw_args *, int, void *); +static inline void rule_recv(int *, ipfw_insn *, struct mbuf *, struct ip_fw_chain *, uint32_t *); +static inline void rule_xmit(int *, struct ifnet *, ipfw_insn *, struct ip_fw_chain *, uint32_t *); +static inline void rule_via(int *, struct ifnet *, struct mbuf *, ipfw_insn *, struct ip_fw_chain *, uint32_t *); +static inline void rule_macaddr2(int *, struct ip_fw_args *, ipfw_insn *); +static inline void rule_mac_type(int *, struct ip_fw_args *, ipfw_insn *, int, uint16_t); +static inline void rule_frag(int *, u_short); +static inline void rule_in(int *, struct ifnet *); +static inline void rule_layer2(int *, struct ip_fw_args *); +static inline void rule_diverted(int *, struct ip_fw_args *, ipfw_insn *); +static inline void rule_proto(int *, uint8_t, ipfw_insn *); +static inline void rule_ip_src(int *, int, ipfw_insn *, struct in_addr *); +static inline void rule_ip_dst_lookup(int *, ipfw_insn *, int, struct ip_fw_args *, uint32_t *, int, int, struct ip *, struct in_addr *, struct in_addr *, uint16_t, uint16_t, u_short, uint8_t, int, void *, struct ip_fw_chain *); +static inline void rule_ip_dst_mask(int *, int, ipfw_insn *, int, struct in_addr *, struct in_addr *); +static inline void rule_ip_src_me(int *, int, int, struct in_addr *, struct ip_fw_args *); + +#ifdef INET6 +static inline void rule_ip6_src_me(int *, int, struct ip_fw_args *); +#endif /* INET6 */ + +static inline void rule_ip_src_set(int *, int, ipfw_insn *, struct ip_fw_args *); +static inline void rule_ip_dst(int *, int, ipfw_insn *, struct in_addr *); +static inline void rule_ip_dst_me(int *, struct ip_fw_args *, int, int, struct in_addr *); + +#ifdef INET6 +static inline void rule_ip6_dst_me(int *, struct ip_fw_args *args, int is_ipv6); +#endif /* INET6 */ + +static inline void rule_ip_dstport(int *, uint8_t, u_short , ipfw_insn *, int , uint16_t , uint16_t); +static inline void rule_icmptype(int *, u_short, uint8_t , void *, ipfw_insn *); + +#ifdef INET6 +static inline void rule_icmp6type(int *, u_short, int, uint8_t, void *, ipfw_insn *); +#endif /* INET6 */ + +static inline void rule_ipopt(int *, int, struct ip *, ipfw_insn *); +static inline void rule_ipver(int *, int, ipfw_insn *, struct ip *); +static inline void rule_ipttl(int *, int, ipfw_insn *, int, struct ip *, uint16_t); +static inline void rule_ipprecedence(int *, int, ipfw_insn *, struct ip *); +static inline void rule_iptos(int *, int, ipfw_insn *, struct ip *); +static inline void rule_dscp(int *, int, int, ipfw_insn *, struct ip *); +static inline void rule_tcpdatalen(int *, uint8_t, u_short, void *, uint16_t, int, ipfw_insn *, struct ip *); +static inline void rule_tcpflags(int *, uint8_t, u_short, ipfw_insn *, void *); +static inline int rule_tcpopts(int *, u_int, void *, uint8_t, u_short, ipfw_insn *, struct mbuf *, struct ip_fw_args *); +static inline void rule_tcpseq(int *, uint8_t, u_short, ipfw_insn *, void *); +static inline void rule_tcpack(int *, uint8_t, u_short, ipfw_insn *, void *); +static inline void rule_tcpwin(int *, uint8_t, u_short, ipfw_insn *, int, void *); +static inline void rule_estab(int *, uint8_t, u_short, void *); +static inline void rule_altq(int *, ipfw_insn *, struct mbuf *, struct ip *); +static inline void rule_log(int *, struct ip_fw *, u_int, struct ip_fw_args *, struct mbuf *, struct ifnet *, u_short, u_short, uint32_t, struct ip *); +static inline void rule_prob(int *, ipfw_insn *); +static inline void rule_verrevpath(int *, struct ifnet *, struct mbuf *, int, struct ip_fw_args *, struct in_addr *); +static inline void rule_versrcreach(int *, u_int, struct ifnet *, int, struct ip_fw_args *, struct in_addr *); +static inline void rule_antispoof(int *, struct ifnet *, u_int, int, int, struct in_addr *, struct ip_fw_args *, struct mbuf *); + +#ifdef IPSEC +static inline void rule_ipsec(int *match, struct mbuf *); +#endif /* IPSEC */ + +#ifdef INET6 +static inline void rule_ip6_src(int *, int, struct ip_fw_args *, ipfw_insn *); +static inline void rule_ip6_dst(int *, int, struct ip_fw_args *, ipfw_insn *); +static inline void rule_ip6_dst_mask(int *, struct ip_fw_args *, ipfw_insn *, int, int); +static inline void rule_flow6id(int *, int, struct ip_fw_args *, ipfw_insn *); +static inline void rule_ext_hdr(int *, int, uint16_t, ipfw_insn *); +static inline void rule_ip6(int *, int); +#endif /* INET6 */ + +static inline void rule_ip4(int *, int); +static inline void rule_tag(int *, ipfw_insn *, struct mbuf *, uint32_t); +static inline void rule_fib(int *, struct ip_fw_args *, ipfw_insn *); +static inline void rule_sockarg(int *, int, uint8_t, struct in_addr *, struct in_addr *, uint16_t, uint16_t, struct ip_fw_args *, uint32_t *); +static inline void rule_tagged(int *, ipfw_insn *, int, struct mbuf *, uint32_t); + +/* The second sets of opcodes. They represent the actions of a rule. */ +static inline void rule_keep_state(int *, struct ip_fw *f, ipfw_insn *, struct ip_fw_args *, uint32_t, int *, int *, int *); +static inline void rule_check_state(int *, int *, ipfw_dyn_rule *, struct ip_fw_args *, uint8_t, void *, int, struct ip_fw *, int *, struct ip_fw_chain *, ipfw_insn *, int *, int *); +static inline void rule_accept(int *, int *, int *); +static inline void rule_queue(struct ip_fw_args *, int, struct ip_fw_chain *, ipfw_insn *, uint32_t, int *, int *, int *); +static inline void rule_tee(int *, int *, int *, ipfw_insn *, struct ip_fw_args *, int, uint32_t, struct ip_fw_chain *); +static inline void rule_count(int *, struct ip_fw *, int); +static inline void rule_skipto(int *, int *, ipfw_insn *, int *, int *, int *, struct ip_fw *, int, struct ip_fw_chain *, uint32_t); +static inline void rule_callreturn(ipfw_insn *, struct mbuf *, struct ip_fw *, struct ip_fw_chain *, uint32_t, int, int *, int *, int *, int *); +static inline void rule_reject(u_int, int, u_short, uint8_t, void *, struct mbuf *, struct in_addr *, struct ip_fw_args *, ipfw_insn *, uint16_t, struct ip *); + +#ifdef INET6 +static inline void rule_unreach6(u_int, int, u_short, uint8_t, uint8_t, struct mbuf *, struct ip_fw_args *, ipfw_insn *, struct ip *); +#endif /* INET6 */ + +static inline void rule_deny(int *, int *, int *); +static inline void rule_forward_ip(struct ip_fw_args *, ipfw_dyn_rule *, struct ip_fw *, int, ipfw_insn *, uint32_t, int *, int *, int *); + +#ifdef INET6 +static inline void rule_forward_ip6(struct ip_fw_args *, ipfw_dyn_rule *, struct ip_fw *, int, ipfw_insn *, int *, int *, int *); +#endif /* INET6 */ + +static inline void rule_ngtee(struct ip_fw_args *, int, struct ip_fw_chain *, ipfw_insn *, uint32_t, int *, int *, int *); +static inline void rule_setfib(struct ip_fw *, int, uint32_t, ipfw_insn *, struct mbuf *, struct ip_fw_args *, int *); +static inline void rule_setdscp(ipfw_insn *, struct ip *, int, int, uint32_t, struct ip_fw *, int, int *); +static inline void rule_nat(struct ip_fw_args *, int, struct ip_fw_chain *, ipfw_insn *, struct mbuf *, uint32_t, int *, int *, int *); +static inline void rule_reass(struct ip_fw *, int, struct ip_fw_chain *, int, struct ip *, struct ip_fw_args *, struct mbuf *, int *, int *, int *); + +/* + * Each rule belongs to one of 32 different sets (0..31). + * The variable set_disable contains one bit per set. + * If the bit is set, all rules in the corresponding set + * are disabled. Set RESVD_SET(31) is reserved for the default rule + * and rules that are not deleted by the flush command, + * and CANNOT be disabled. + * Rules in set RESVD_SET can only be deleted individually. + */ +VNET_DEFINE(u_int32_t, set_disable); +#define V_set_disable VNET(set_disable) + +VNET_DEFINE(int, fw_verbose); +/* counter for ipfw_log(NULL...) */ +VNET_DEFINE(u_int64_t, norule_counter); +VNET_DEFINE(int, verbose_limit); + +/* layer3_chain contains the list of rules for layer 3 */ +VNET_DEFINE(struct ip_fw_chain, layer3_chain); + +VNET_DEFINE(int, ipfw_nat_ready) = 0; + +ipfw_nat_t *ipfw_nat_ptr = NULL; +struct cfg_nat *(*lookup_nat_ptr)(struct nat_list *, int); +ipfw_nat_cfg_t *ipfw_nat_cfg_ptr; +ipfw_nat_cfg_t *ipfw_nat_del_ptr; +ipfw_nat_cfg_t *ipfw_nat_get_cfg_ptr; +ipfw_nat_cfg_t *ipfw_nat_get_log_ptr; + +#ifdef SYSCTL_NODE +uint32_t dummy_def = IPFW_DEFAULT_RULE; +static int sysctl_ipfw_table_num(SYSCTL_HANDLER_ARGS); + +SYSBEGIN(f3) + +SYSCTL_NODE(_net_inet_ip, OID_AUTO, fw, CTLFLAG_RW, 0, "Firewall"); +SYSCTL_VNET_INT(_net_inet_ip_fw, OID_AUTO, one_pass, + CTLFLAG_RW | CTLFLAG_SECURE3, &VNET_NAME(fw_one_pass), 0, + "Only do a single pass through ipfw when using dummynet(4)"); +SYSCTL_VNET_INT(_net_inet_ip_fw, OID_AUTO, autoinc_step, + CTLFLAG_RW, &VNET_NAME(autoinc_step), 0, + "Rule number auto-increment step"); +SYSCTL_VNET_INT(_net_inet_ip_fw, OID_AUTO, verbose, + CTLFLAG_RW | CTLFLAG_SECURE3, &VNET_NAME(fw_verbose), 0, + "Log matches to ipfw rules"); +SYSCTL_VNET_INT(_net_inet_ip_fw, OID_AUTO, verbose_limit, + CTLFLAG_RW, &VNET_NAME(verbose_limit), 0, + "Set upper limit of matches of ipfw rules logged"); +SYSCTL_UINT(_net_inet_ip_fw, OID_AUTO, default_rule, CTLFLAG_RD, + &dummy_def, 0, + "The default/max possible rule number."); +SYSCTL_VNET_PROC(_net_inet_ip_fw, OID_AUTO, tables_max, + CTLTYPE_UINT|CTLFLAG_RW, 0, 0, sysctl_ipfw_table_num, "IU", + "Maximum number of tables"); +SYSCTL_INT(_net_inet_ip_fw, OID_AUTO, default_to_accept, CTLFLAG_RDTUN, + &default_to_accept, 0, + "Make the default rule accept all packets."); +TUNABLE_INT("net.inet.ip.fw.default_to_accept", &default_to_accept); +TUNABLE_INT("net.inet.ip.fw.tables_max", (int *)&default_fw_tables); +SYSCTL_VNET_INT(_net_inet_ip_fw, OID_AUTO, static_count, + CTLFLAG_RD, &VNET_NAME(layer3_chain.n_rules), 0, + "Number of static rules"); + +#ifdef INET6 +SYSCTL_DECL(_net_inet6_ip6); +SYSCTL_NODE(_net_inet6_ip6, OID_AUTO, fw, CTLFLAG_RW, 0, "Firewall"); +SYSCTL_VNET_INT(_net_inet6_ip6_fw, OID_AUTO, deny_unknown_exthdrs, + CTLFLAG_RW | CTLFLAG_SECURE, &VNET_NAME(fw_deny_unknown_exthdrs), 0, + "Deny packets with unknown IPv6 Extension Headers"); +SYSCTL_VNET_INT(_net_inet6_ip6_fw, OID_AUTO, permit_single_frag6, + CTLFLAG_RW | CTLFLAG_SECURE, &VNET_NAME(fw_permit_single_frag6), 0, + "Permit single packet IPv6 fragments"); +#endif /* INET6 */ + +SYSEND + +#endif /* SYSCTL_NODE */ + + +/* + * Some macros used in the various matching options. + * L3HDR maps an ipv4 pointer into a layer3 header pointer of type T + * Other macros just cast void * into the appropriate type + */ +#define L3HDR(T, ip) ((T *)((u_int32_t *)(ip) + (ip)->ip_hl)) +#define TCP(p) ((struct tcphdr *)(p)) +#define SCTP(p) ((struct sctphdr *)(p)) +#define UDP(p) ((struct udphdr *)(p)) +#define ICMP(p) ((struct icmphdr *)(p)) +#define ICMP6(p) ((struct icmp6_hdr *)(p)) + +/* + * The main check routine for the firewall. + * + * All arguments are in args so we can modify them and return them + * back to the caller. + * + * Parameters: + * + * args->m (in/out) The packet; we set to NULL when/if we nuke it. + * Starts with the IP header. + * args->eh (in) Mac header if present, NULL for layer3 packet. + * args->L3offset Number of bytes bypassed if we came from L2. + * e.g. often sizeof(eh) ** NOTYET ** + * args->oif Outgoing interface, NULL if packet is incoming. + * The incoming interface is in the mbuf. (in) + * args->divert_rule (in/out) + * Skip up to the first rule past this rule number; + * upon return, non-zero port number for divert or tee. + * + * args->rule Pointer to the last matching rule (in/out) + * args->next_hop Socket we are forwarding to (out). + * args->next_hop6 IPv6 next hop we are forwarding to (out). + * args->f_id Addresses grabbed from the packet (out) + * args->rule.info a cookie depending on rule action + * + * Return value: + * + * IP_FW_PASS the packet must be accepted + * IP_FW_DENY the packet must be dropped + * IP_FW_DIVERT divert packet, port in m_tag + * IP_FW_TEE tee packet, port in m_tag + * IP_FW_DUMMYNET to dummynet, pipe in args->cookie + * IP_FW_NETGRAPH into netgraph, cookie args->cookie + * args->rule contains the matching rule, + * args->rule.info has additional information. + * + */ +int +ipfw_chk(struct ip_fw_args *args) +{ + + /* + * Local variables holding state while processing a packet: + * + * IMPORTANT NOTE: to speed up the processing of rules, there + * are some assumption on the values of the variables, which + * are documented here. Should you change them, please check + * the implementation of the various instructions to make sure + * that they still work. + * + * args->eh The MAC header. It is non-null for a layer2 + * packet, it is NULL for a layer-3 packet. + * **notyet** + * args->L3offset Offset in the packet to the L3 (IP or equiv.) header. + * + * m | args->m Pointer to the mbuf, as received from the caller. + * It may change if ipfw_chk() does an m_pullup, or if it + * consumes the packet because it calls send_reject(). + * XXX This has to change, so that ipfw_chk() never modifies + * or consumes the buffer. + * ip is the beginning of the ip(4 or 6) header. + * Calculated by adding the L3offset to the start of data. + * (Until we start using L3offset, the packet is + * supposed to start with the ip header). + */ + struct mbuf *m = args->m; + struct ip *ip = mtod(m, struct ip *); + + /* + * For rules which contain uid/gid or jail constraints, cache + * a copy of the users credentials after the pcb lookup has been + * executed. This will speed up the processing of rules with + * these types of constraints, as well as decrease contention + * on pcb related locks. + */ +#ifndef __FreeBSD__ + struct bsd_ucred ucred_cache; +#else + struct ucred *ucred_cache = NULL; +#endif + int ucred_lookup = 0; + + /* + * oif | args->oif If NULL, ipfw_chk has been called on the + * inbound path (ether_input, ip_input). + * If non-NULL, ipfw_chk has been called on the outbound path + * (ether_output, ip_output). + */ + struct ifnet *oif = args->oif; + + int f_pos = 0; /* index of current rule in the array */ + int retval = 0; + + /* + * hlen The length of the IP header. + */ + u_int hlen = 0; /* hlen >0 means we have an IP pkt */ + + /* + * offset The offset of a fragment. offset != 0 means that + * we have a fragment at this offset of an IPv4 packet. + * offset == 0 means that (if this is an IPv4 packet) + * this is the first or only fragment. + * For IPv6 offset|ip6f_mf == 0 means there is no Fragment Header + * or there is a single packet fragement (fragement header added + * without needed). We will treat a single packet fragment as if + * there was no fragment header (or log/block depending on the + * V_fw_permit_single_frag6 sysctl setting). + */ + u_short offset = 0; + u_short ip6f_mf = 0; + + /* + * Local copies of addresses. They are only valid if we have + * an IP packet. + * + * proto The protocol. Set to 0 for non-ip packets, + * or to the protocol read from the packet otherwise. + * proto != 0 means that we have an IPv4 packet. + * + * src_port, dst_port port numbers, in HOST format. Only + * valid for TCP and UDP packets. + * + * src_ip, dst_ip ip addresses, in NETWORK format. + * Only valid for IPv4 packets. + */ + uint8_t proto; + uint16_t src_port = 0, dst_port = 0; /* NOTE: host format */ + struct in_addr src_ip, dst_ip; /* NOTE: network format */ + uint16_t iplen=0; + int pktlen; + uint16_t etype = 0; /* Host order stored ether type */ + + /* + * dyn_dir = MATCH_UNKNOWN when rules unchecked, + * MATCH_NONE when checked and not matched (q = NULL), + * MATCH_FORWARD or MATCH_REVERSE otherwise (q != NULL) + */ + int dyn_dir = MATCH_UNKNOWN; + ipfw_dyn_rule *q = NULL; + struct ip_fw_chain *chain = &V_layer3_chain; + + /* + * We store in ulp a pointer to the upper layer protocol header. + * In the ipv4 case this is easy to determine from the header, + * but for ipv6 we might have some additional headers in the middle. + * ulp is NULL if not found. + */ + void *ulp = NULL; /* upper layer protocol pointer. */ + + /* XXX ipv6 variables */ + int is_ipv6 = 0; + uint8_t icmp6_type = 0; + uint16_t ext_hd = 0; /* bits vector for extension header filtering */ + /* end of ipv6 variables */ + + int is_ipv4 = 0; + + int done = 0; /* flag to exit the outer loop */ + + if (m->m_flags & M_SKIP_FIREWALL || (! V_ipfw_vnet_ready)) + return (IP_FW_PASS); /* accept */ + + dst_ip.s_addr = 0; /* make sure it is initialized */ + src_ip.s_addr = 0; /* make sure it is initialized */ + pktlen = m->m_pkthdr.len; + args->f_id.fib = M_GETFIB(m); /* note mbuf not altered) */ + proto = args->f_id.proto = 0; /* mark f_id invalid */ + /* XXX 0 is a valid proto: IP/IPv6 Hop-by-Hop Option */ + +/* + * PULLUP_TO(len, p, T) makes sure that len + sizeof(T) is contiguous, + * then it sets p to point at the offset "len" in the mbuf. WARNING: the + * pointer might become stale after other pullups (but we never use it + * this way). + */ +#define PULLUP_TO(_len, p, T) PULLUP_LEN(_len, p, sizeof(T)) +#define PULLUP_LEN(_len, p, T) \ +do { \ + int x = (_len) + T; \ + if ((m)->m_len < x) { \ + args->m = m = m_pullup(m, x); \ + if (m == NULL) \ + goto pullup_failed; \ + } \ + p = (mtod(m, char *) + (_len)); \ +} while (0) + + /* + * if we have an ether header, + */ + if (args->eh) + etype = ntohs(args->eh->ether_type); + + /* Identify IP packets and fill up variables. */ + if (pktlen >= sizeof(struct ip6_hdr) && + (args->eh == NULL || etype == ETHERTYPE_IPV6) && ip->ip_v == 6) { + struct ip6_hdr *ip6 = (struct ip6_hdr *)ip; + is_ipv6 = 1; + args->f_id.addr_type = 6; + hlen = sizeof(struct ip6_hdr); + proto = ip6->ip6_nxt; + + /* Search extension headers to find upper layer protocols */ + while (ulp == NULL && offset == 0) { + switch (proto) { + case IPPROTO_ICMPV6: + PULLUP_TO(hlen, ulp, struct icmp6_hdr); + icmp6_type = ICMP6(ulp)->icmp6_type; + break; + + case IPPROTO_TCP: + PULLUP_TO(hlen, ulp, struct tcphdr); + dst_port = TCP(ulp)->th_dport; + src_port = TCP(ulp)->th_sport; + /* save flags for dynamic rules */ + args->f_id._flags = TCP(ulp)->th_flags; + break; + + case IPPROTO_SCTP: + PULLUP_TO(hlen, ulp, struct sctphdr); + src_port = SCTP(ulp)->src_port; + dst_port = SCTP(ulp)->dest_port; + break; + + case IPPROTO_UDP: + PULLUP_TO(hlen, ulp, struct udphdr); + dst_port = UDP(ulp)->uh_dport; + src_port = UDP(ulp)->uh_sport; + break; + + case IPPROTO_HOPOPTS: /* RFC 2460 */ + PULLUP_TO(hlen, ulp, struct ip6_hbh); + ext_hd |= EXT_HOPOPTS; + hlen += (((struct ip6_hbh *)ulp)->ip6h_len + 1) << 3; + proto = ((struct ip6_hbh *)ulp)->ip6h_nxt; + ulp = NULL; + break; + + case IPPROTO_ROUTING: /* RFC 2460 */ + PULLUP_TO(hlen, ulp, struct ip6_rthdr); + switch (((struct ip6_rthdr *)ulp)->ip6r_type) { + case 0: + ext_hd |= EXT_RTHDR0; + break; + case 2: + ext_hd |= EXT_RTHDR2; + break; + default: + if (V_fw_verbose) + printf("IPFW2: IPV6 - Unknown " + "Routing Header type(%d)\n", + ((struct ip6_rthdr *) + ulp)->ip6r_type); + if (V_fw_deny_unknown_exthdrs) + return (IP_FW_DENY); + break; + } + ext_hd |= EXT_ROUTING; + hlen += (((struct ip6_rthdr *)ulp)->ip6r_len + 1) << 3; + proto = ((struct ip6_rthdr *)ulp)->ip6r_nxt; + ulp = NULL; + break; + + case IPPROTO_FRAGMENT: /* RFC 2460 */ + PULLUP_TO(hlen, ulp, struct ip6_frag); + ext_hd |= EXT_FRAGMENT; + hlen += sizeof (struct ip6_frag); + proto = ((struct ip6_frag *)ulp)->ip6f_nxt; + offset = ((struct ip6_frag *)ulp)->ip6f_offlg & + IP6F_OFF_MASK; + ip6f_mf = ((struct ip6_frag *)ulp)->ip6f_offlg & + IP6F_MORE_FRAG; + if (V_fw_permit_single_frag6 == 0 && + offset == 0 && ip6f_mf == 0) { + if (V_fw_verbose) + printf("IPFW2: IPV6 - Invalid " + "Fragment Header\n"); + if (V_fw_deny_unknown_exthdrs) + return (IP_FW_DENY); + break; + } + args->f_id.extra = + ntohl(((struct ip6_frag *)ulp)->ip6f_ident); + ulp = NULL; + break; + + case IPPROTO_DSTOPTS: /* RFC 2460 */ + PULLUP_TO(hlen, ulp, struct ip6_hbh); + ext_hd |= EXT_DSTOPTS; + hlen += (((struct ip6_hbh *)ulp)->ip6h_len + 1) << 3; + proto = ((struct ip6_hbh *)ulp)->ip6h_nxt; + ulp = NULL; + break; + + case IPPROTO_AH: /* RFC 2402 */ + PULLUP_TO(hlen, ulp, struct ip6_ext); + ext_hd |= EXT_AH; + hlen += (((struct ip6_ext *)ulp)->ip6e_len + 2) << 2; + proto = ((struct ip6_ext *)ulp)->ip6e_nxt; + ulp = NULL; + break; + + case IPPROTO_ESP: /* RFC 2406 */ + PULLUP_TO(hlen, ulp, uint32_t); /* SPI, Seq# */ + /* Anything past Seq# is variable length and + * data past this ext. header is encrypted. */ + ext_hd |= EXT_ESP; + break; + + case IPPROTO_NONE: /* RFC 2460 */ + /* + * Packet ends here, and IPv6 header has + * already been pulled up. If ip6e_len!=0 + * then octets must be ignored. + */ + ulp = ip; /* non-NULL to get out of loop. */ + break; + + case IPPROTO_OSPFIGP: + /* XXX OSPF header check? */ + PULLUP_TO(hlen, ulp, struct ip6_ext); + break; + + case IPPROTO_PIM: + /* XXX PIM header check? */ + PULLUP_TO(hlen, ulp, struct pim); + break; + + case IPPROTO_CARP: + PULLUP_TO(hlen, ulp, struct carp_header); + if (((struct carp_header *)ulp)->carp_version != + CARP_VERSION) + return (IP_FW_DENY); + if (((struct carp_header *)ulp)->carp_type != + CARP_ADVERTISEMENT) + return (IP_FW_DENY); + break; + + case IPPROTO_IPV6: /* RFC 2893 */ + PULLUP_TO(hlen, ulp, struct ip6_hdr); + break; + + case IPPROTO_IPV4: /* RFC 2893 */ + PULLUP_TO(hlen, ulp, struct ip); + break; + + default: + if (V_fw_verbose) + printf("IPFW2: IPV6 - Unknown " + "Extension Header(%d), ext_hd=%x\n", + proto, ext_hd); + if (V_fw_deny_unknown_exthdrs) + return (IP_FW_DENY); + PULLUP_TO(hlen, ulp, struct ip6_ext); + break; + } /*switch */ + } + ip = mtod(m, struct ip *); + ip6 = (struct ip6_hdr *)ip; + args->f_id.src_ip6 = ip6->ip6_src; + args->f_id.dst_ip6 = ip6->ip6_dst; + args->f_id.src_ip = 0; + args->f_id.dst_ip = 0; + args->f_id.flow_id6 = ntohl(ip6->ip6_flow); + } else if (pktlen >= sizeof(struct ip) && + (args->eh == NULL || etype == ETHERTYPE_IP) && ip->ip_v == 4) { + is_ipv4 = 1; + hlen = ip->ip_hl << 2; + args->f_id.addr_type = 4; + + /* + * Collect parameters into local variables for faster matching. + */ + proto = ip->ip_p; + src_ip = ip->ip_src; + dst_ip = ip->ip_dst; + offset = ntohs(ip->ip_off) & IP_OFFMASK; + iplen = ntohs(ip->ip_len); + pktlen = iplen < pktlen ? iplen : pktlen; + + if (offset == 0) { + switch (proto) { + case IPPROTO_TCP: + PULLUP_TO(hlen, ulp, struct tcphdr); + dst_port = TCP(ulp)->th_dport; + src_port = TCP(ulp)->th_sport; + /* save flags for dynamic rules */ + args->f_id._flags = TCP(ulp)->th_flags; + break; + + case IPPROTO_SCTP: + PULLUP_TO(hlen, ulp, struct sctphdr); + src_port = SCTP(ulp)->src_port; + dst_port = SCTP(ulp)->dest_port; + break; + + case IPPROTO_UDP: + PULLUP_TO(hlen, ulp, struct udphdr); + dst_port = UDP(ulp)->uh_dport; + src_port = UDP(ulp)->uh_sport; + break; + + case IPPROTO_ICMP: + PULLUP_TO(hlen, ulp, struct icmphdr); + //args->f_id.flags = ICMP(ulp)->icmp_type; + break; + + default: + break; + } + } + + ip = mtod(m, struct ip *); + args->f_id.src_ip = ntohl(src_ip.s_addr); + args->f_id.dst_ip = ntohl(dst_ip.s_addr); + } +#undef PULLUP_TO + if (proto) { /* we may have port numbers, store them */ + args->f_id.proto = proto; + args->f_id.src_port = src_port = ntohs(src_port); + args->f_id.dst_port = dst_port = ntohs(dst_port); + } + + IPFW_PF_RLOCK(chain); + if (! V_ipfw_vnet_ready) { /* shutting down, leave NOW. */ + IPFW_PF_RUNLOCK(chain); + return (IP_FW_PASS); /* accept */ + } + if (args->rule.slot) { + /* + * Packet has already been tagged as a result of a previous + * match on rule args->rule aka args->rule_id (PIPE, QUEUE, + * REASS, NETGRAPH, DIVERT/TEE...) + * Validate the slot and continue from the next one + * if still present, otherwise do a lookup. + */ + f_pos = (args->rule.chain_id == chain->id) ? + args->rule.slot : + ipfw_find_rule(chain, args->rule.rulenum, + args->rule.rule_id); + } else { + f_pos = 0; + } + + /* + * Now scan the rules, and parse microinstructions for each rule. + * We have two nested loops and an inner switch. Sometimes we + * need to break out of one or both loops, or re-enter one of + * the loops with updated variables. Loop variables are: + * + * f_pos (outer loop) points to the current rule. + * On output it points to the matching rule. + * done (outer loop) is used as a flag to break the loop. + * l (inner loop) residual length of current rule. + * cmd points to the current microinstruction. + * + * We break the inner loop by setting l=0 and possibly + * cmdlen=0 if we don't want to advance cmd. + * We break the outer loop by setting done=1 + * We can restart the inner loop by setting l>0 and f_pos, f, cmd + * as needed. + */ + for (; f_pos < chain->n_rules; f_pos++) { + ipfw_insn *cmd; + uint32_t tablearg = 0; + int l, cmdlen, skip_or; /* skip rest of OR block */ + struct ip_fw *f; + + f = chain->map[f_pos]; + if (V_set_disable & (1 << f->set) ) + continue; + + skip_or = 0; + for (l = f->cmd_len, cmd = f->cmd ; l > 0 ; + l -= cmdlen, cmd += cmdlen) { + int match; + + /* + * check_body is a jump target used when we find a + * CHECK_STATE, and need to jump to the body of + * the target rule. + */ + +/* check_body: */ + cmdlen = F_LEN(cmd); + /* + * An OR block (insn_1 || .. || insn_n) has the + * F_OR bit set in all but the last instruction. + * The first match will set "skip_or", and cause + * the following instructions to be skipped until + * past the one with the F_OR bit clear. + */ + if (skip_or) { /* skip this instruction */ + if ((cmd->len & F_OR) == 0) + skip_or = 0; /* next one is good */ + continue; + } + match = 0; /* set to 1 if we succeed */ + + switch (cmd->opcode) { + /* + * The first set of opcodes compares the packet's + * fields with some pattern, setting 'match' if a + * match is found. At the end of the loop there is + * logic to deal with F_NOT and F_OR flags associated + * with the opcode. + */ + case O_NOP: + rule_nop(&match); + break; + + case O_FORWARD_MAC: + rule_forward_mac(cmd->opcode); + break; + + case O_GID: + case O_UID: + case O_JAIL: + rule_jail(&match, offset, proto, cmd, args, ucred_lookup, ucred_cache); + break; + + case O_RECV: + rule_recv(&match, cmd, m, chain, &tablearg); + break; + + case O_XMIT: + rule_xmit(&match, oif, cmd, chain, &tablearg); + break; + + case O_VIA: + rule_via(&match, oif, m, cmd, chain, &tablearg); + break; + + case O_MACADDR2: + rule_macaddr2(&match, args, cmd); + break; + + case O_MAC_TYPE: + rule_mac_type(&match, args, cmd, cmdlen, etype); + break; + + case O_FRAG: + rule_frag(&match, offset); + break; + + case O_IN: + rule_in(&match, oif); + break; + + case O_LAYER2: + rule_layer2(&match, args); + break; + + case O_DIVERTED: + rule_diverted(&match, args, cmd); + break; + + case O_PROTO: + rule_proto(&match, proto, cmd); + break; + + case O_IP_SRC: + rule_ip_src(&match, is_ipv4, cmd, &src_ip); + break; + + case O_IP_SRC_LOOKUP: + case O_IP_DST_LOOKUP: + rule_ip_dst_lookup(&match, cmd, cmdlen, args, &tablearg, is_ipv4, is_ipv6, ip, &dst_ip, &src_ip, dst_port, src_port, offset, proto, ucred_lookup, ucred_cache, chain); + break; + + case O_IP_SRC_MASK: + case O_IP_DST_MASK: + rule_ip_dst_mask(&match, is_ipv4, cmd, cmdlen, &dst_ip, &src_ip); + break; + + case O_IP_SRC_ME: + rule_ip_src_me(&match, is_ipv4, is_ipv6, &src_ip, args); +#ifdef INET6 + /* FALLTHROUGH */ + case O_IP6_SRC_ME: + rule_ip6_src_me(&match, is_ipv6, args); +#endif + break; + + case O_IP_DST_SET: + case O_IP_SRC_SET: + rule_ip_src_set(&match, is_ipv4, cmd, args); + break; + + case O_IP_DST: + rule_ip_dst(&match, is_ipv4, cmd, &dst_ip); + break; + + case O_IP_DST_ME: + rule_ip_dst_me(&match, args, is_ipv4, is_ipv6, &dst_ip); + +#ifdef INET6 + /* FALLTHROUGH */ + case O_IP6_DST_ME: + rule_ip6_dst_me(&match, args, is_ipv6); +#endif + break; + + + case O_IP_SRCPORT: + case O_IP_DSTPORT: + rule_ip_dstport(&match, proto, offset, cmd, cmdlen, dst_port, src_port); + break; + + case O_ICMPTYPE: + rule_icmptype(&match, offset, proto, ulp, cmd); + break; + +#ifdef INET6 + case O_ICMP6TYPE: + rule_icmp6type(&match, offset, is_ipv6, proto, ulp, cmd); + break; +#endif /* INET6 */ + + case O_IPOPT: + rule_ipopt(&match, is_ipv4, ip, cmd); + break; *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-soc-all@FreeBSD.ORG Fri Jul 18 07:40:25 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id EA8CA2BE for ; Fri, 18 Jul 2014 07:40:25 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D800C2441 for ; Fri, 18 Jul 2014 07:40:25 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6I7ePa9043466 for ; Fri, 18 Jul 2014 07:40:25 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s6I7ePce043462 for svn-soc-all@FreeBSD.org; Fri, 18 Jul 2014 07:40:25 GMT (envelope-from op@FreeBSD.org) Date: Fri, 18 Jul 2014 07:40:25 GMT Message-Id: <201407180740.s6I7ePce043462@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271051 - soc2014/op/tools MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jul 2014 07:40:26 -0000 Author: op Date: Fri Jul 18 07:40:24 2014 New Revision: 271051 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271051 Log: updated build tools Signed-off-by: Oliver Pinter Modified: soc2014/op/tools/build_kernel_32bit.csh soc2014/op/tools/build_kernel_64bit.csh Modified: soc2014/op/tools/build_kernel_32bit.csh ============================================================================== --- soc2014/op/tools/build_kernel_32bit.csh Fri Jul 18 06:58:01 2014 (r271050) +++ soc2014/op/tools/build_kernel_32bit.csh Fri Jul 18 07:40:24 2014 (r271051) @@ -2,14 +2,16 @@ setenv TARGET i386 setenv TARGET_ARCH i386 -setenv MAKEOBJDIRPREFIX "/tmp/objdir_${TARGET}" -setenv DESTDIR /tmp/kernelbuild +setenv __MAKE_CONF /dev/null +setenv MAKEOBJDIRPREFIX "/tmp/${TARGET}-objdir" +setenv DESTDIR /tmp/${TARGET}-kernel @ __freebsd_mk_jobs = `sysctl -n kern.smp.cpus` + 1 set current_dir = `pwd` set _current_dir = `echo ${current_dir} | sed -e 's|\(.*/\)\(.*\.git\)\(/.*\)*|\2|g'` set _current_realdir = `echo ${current_dir} | sed -e 's|\(.*/\)\(.*\.git\)\(/.*\)*|\1/\2|g'` set _check_toolchain = "${MAKEOBJDIRPREFIX}/___kernel-toolchain_DONE" set _date=`date "+%Y%m%d%H%M%S"` +set _log="/tmp/${TARGET}-cc-log-${_current_dir}-${_date}" if ( "`sysctl -n security.bsd.hardlink_check_uid`" == "1" ) then echo "build will fail, due to hard security checks" @@ -37,10 +39,10 @@ endif if ( ! -f ${_check_toolchain} ) then - (cd /usr/data/source/git/opBSD/${_current_dir}; make -j$__freebsd_mk_jobs -DNO_ROOT KERNCONF=GENERIC kernel-toolchain) |& tee /tmp/cc-log-${_current_dir}-${_date} || exit + (cd /usr/data/source/git/opBSD/${_current_dir}; make -j$__freebsd_mk_jobs -DNO_ROOT KERNCONF=GENERIC kernel-toolchain) |& tee ${_log} || exit touch ${_check_toolchain} else echo "skip make kernel-toolchain" sleep 1 endif -(cd /usr/data/source/git/opBSD/${_current_dir}; make -j$__freebsd_mk_jobs -DNO_ROOT KERNCONF=GENERIC buildkernel) |& tee -a /tmp/cc-log-${_current_dir}-${_date} +(cd /usr/data/source/git/opBSD/${_current_dir}; make -j$__freebsd_mk_jobs -DNO_ROOT KERNCONF=GENERIC kernel) |& tee -a ${_log} Modified: soc2014/op/tools/build_kernel_64bit.csh ============================================================================== --- soc2014/op/tools/build_kernel_64bit.csh Fri Jul 18 06:58:01 2014 (r271050) +++ soc2014/op/tools/build_kernel_64bit.csh Fri Jul 18 07:40:24 2014 (r271051) @@ -1,13 +1,16 @@ #!/bin/csh -setenv MAKEOBJDIRPREFIX /tmp/objdir -setenv DESTDIR /tmp/kernelbuild +setenv TARGET amd64 +setenv MAKEOBJDIRPREFIX /tmp/${TARGET}-objdir +setenv __MAKE_CONF /dev/null +setenv DESTDIR /tmp/${TARGET}-kernel @ __freebsd_mk_jobs = `sysctl -n kern.smp.cpus` + 1 set current_dir = `pwd` set _current_dir = `echo ${current_dir} | sed -e 's|\(.*/\)\(.*\.git\)\(/.*\)*|\2|g'` set _current_realdir = `echo ${current_dir} | sed -e 's|\(.*/\)\(.*\.git\)\(/.*\)*|\1/\2|g'` set _check_toolchain = "${MAKEOBJDIRPREFIX}/___kernel-toolchain_DONE" set _date=`date "+%Y%m%d%H%M%S"` +set _log="/tmp/${TARGET}-cc-log-${_current_dir}-${_date}" if ( "`sysctl -n security.bsd.hardlink_check_uid`" == "1" ) then echo "build will fail, due to hard security checks" @@ -35,10 +38,10 @@ endif if ( ! -f ${_check_toolchain} ) then - (cd /usr/data/source/git/opBSD/${_current_dir}; make -j$__freebsd_mk_jobs -DNO_ROOT KERNCONF=GENERIC kernel-toolchain) |& tee /tmp/cc-log-${_current_dir}-${_date} || exit + (cd /usr/data/source/git/opBSD/${_current_dir}; make -j$__freebsd_mk_jobs -DNO_ROOT KERNCONF=GENERIC kernel-toolchain) |& tee ${_log} || exit touch ${_check_toolchain} else echo "skip make kernel-toolchain" sleep 1 endif -(cd /usr/data/source/git/opBSD/${_current_dir}; make -j$__freebsd_mk_jobs -DNO_ROOT KERNCONF=GENERIC buildkernel) |& tee -a /tmp/cc-log-${_current_dir}-${_date} +(cd /usr/data/source/git/opBSD/${_current_dir}; make -j$__freebsd_mk_jobs -DNO_ROOT KERNCONF=GENERIC kernel) |& tee -a ${_log} From owner-svn-soc-all@FreeBSD.ORG Fri Jul 18 07:41:08 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 8E81A3CA for ; Fri, 18 Jul 2014 07:41:08 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 57693245E for ; Fri, 18 Jul 2014 07:41:08 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6I7f8Vd045757 for ; Fri, 18 Jul 2014 07:41:08 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s6I7f7fl045752 for svn-soc-all@FreeBSD.org; Fri, 18 Jul 2014 07:41:07 GMT (envelope-from op@FreeBSD.org) Date: Fri, 18 Jul 2014 07:41:07 GMT Message-Id: <201407180741.s6I7f7fl045752@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271052 - soc2014/op/tools MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jul 2014 07:41:08 -0000 Author: op Date: Fri Jul 18 07:41:07 2014 New Revision: 271052 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271052 Log: added faster build script Signed-off-by: Oliver Pinter Added: soc2014/op/tools/build_kernel_64bit_dirty.csh (contents, props changed) Added: soc2014/op/tools/build_kernel_64bit_dirty.csh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/op/tools/build_kernel_64bit_dirty.csh Fri Jul 18 07:41:07 2014 (r271052) @@ -0,0 +1,47 @@ +#!/bin/csh + +setenv TARGET amd64 +setenv MAKEOBJDIRPREFIX /tmp/${TARGET}-objdir +setenv DESTDIR /tmp/${TARGET}-kernel +setenv __MAKE_CONF /dev/null +@ __freebsd_mk_jobs = `sysctl -n kern.smp.cpus` + 1 +set current_dir = `pwd` +set _current_dir = `echo ${current_dir} | sed -e 's|\(.*/\)\(.*\.git\)\(/.*\)*|\2|g'` +set _current_realdir = `echo ${current_dir} | sed -e 's|\(.*/\)\(.*\.git\)\(/.*\)*|\1/\2|g'` +set _check_toolchain = "${MAKEOBJDIRPREFIX}/___kernel-toolchain_DONE" +set _date=`date "+%Y%m%d%H%M%S"` +set _log="/tmp/${TARGET}-cc-log-${_current_dir}-${_date}" + +if ( "`sysctl -n security.bsd.hardlink_check_uid`" == "1" ) then + echo "build will fail, due to hard security checks" + echo "sysctl security.bsd.hardlink_check_uid=0" + exit +endif + +if ( "`sysctl -n security.bsd.hardlink_check_gid`" == "1" ) then + echo "build will fail, due to hard security checks" + echo "sysctl security.bsd.hardlink_check_gid=0" + exit +endif + +if ( (${_current_dir} != "hardenedBSD.git")) then + if ((${_current_dir} != "opBSD.git")) then + set _current_dir = "hardenedBSD.git" + endif +endif + +echo "build source dir: ${_current_dir}" +sleep 1 + +if ( ! -d $MAKEOBJDIRPREFIX ) then + mkdir $MAKEOBJDIRPREFIX +endif + +if ( ! -f ${_check_toolchain} ) then + (cd /usr/data/source/git/opBSD/${_current_dir}; make -j$__freebsd_mk_jobs -DNO_ROOT KERNCONF=GENERIC kernel-toolchain) |& tee ${_log} || exit + touch ${_check_toolchain} +else + echo "skip make kernel-toolchain" + sleep 1 +endif +(cd /usr/data/source/git/opBSD/${_current_dir}; make -j$__freebsd_mk_jobs -DNO_ROOT -DNO_CLEAN KERNCONF=GENERIC kernel) |& tee -a ${_log} From owner-svn-soc-all@FreeBSD.ORG Fri Jul 18 07:47:48 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 7F3D2695 for ; Fri, 18 Jul 2014 07:47:48 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 611CC2507 for ; Fri, 18 Jul 2014 07:47:48 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6I7lmmq052725 for ; Fri, 18 Jul 2014 07:47:48 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s6I7llCU052698 for svn-soc-all@FreeBSD.org; Fri, 18 Jul 2014 07:47:47 GMT (envelope-from op@FreeBSD.org) Date: Fri, 18 Jul 2014 07:47:47 GMT Message-Id: <201407180747.s6I7llCU052698@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271053 - in soc2014/op/freebsd-base/sys: conf kern sys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jul 2014 07:47:48 -0000 Author: op Date: Fri Jul 18 07:47:46 2014 New Revision: 271053 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271053 Log: KSP: added basic structures and files git: https://github.com/opntr/opBSD/tree/op/gsoc2014/kpatch Signed-off-by: Oliver Pinter --- sys/conf/files.amd64 | 1 + sys/kern/kern_selfpatch.c | 39 +++++++++++++++++++++++++++++++++++++++ sys/sys/selfpatch.h | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 sys/kern/kern_selfpatch.c create mode 100644 sys/sys/selfpatch.h Added: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c soc2014/op/freebsd-base/sys/sys/selfpatch.h Modified: soc2014/op/freebsd-base/sys/conf/files.amd64 Modified: soc2014/op/freebsd-base/sys/conf/files.amd64 ============================================================================== --- soc2014/op/freebsd-base/sys/conf/files.amd64 Fri Jul 18 07:41:07 2014 (r271052) +++ soc2014/op/freebsd-base/sys/conf/files.amd64 Fri Jul 18 07:47:46 2014 (r271053) @@ -439,6 +439,7 @@ isa/syscons_isa.c optional sc isa/vga_isa.c optional vga kern/kern_clocksource.c standard +kern/kern_selfpatch.c standard kern/link_elf_obj.c standard # # IA32 binary support Added: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 07:47:46 2014 (r271053) @@ -0,0 +1,39 @@ +/*- + * Copyright (c) 2014, by Oliver Pinter + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include + +#include +#include +#include +#include + +#include +#include + +#include Added: soc2014/op/freebsd-base/sys/sys/selfpatch.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/op/freebsd-base/sys/sys/selfpatch.h Fri Jul 18 07:47:46 2014 (r271053) @@ -0,0 +1,35 @@ +/*- + * Copyright (c) 2014, by Oliver Pinter + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +typedef struct lf_selfpatch { + void *patchable; + void *patch; + short feature_selector; + int feature; + char *comment; +} lf_selfpatch_t; From owner-svn-soc-all@FreeBSD.ORG Fri Jul 18 08:20:33 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 5A404589 for ; Fri, 18 Jul 2014 08:20:33 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 461D1281B for ; Fri, 18 Jul 2014 08:20:33 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6I8KXAL032248 for ; Fri, 18 Jul 2014 08:20:33 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s6I8KVuQ031526 for svn-soc-all@FreeBSD.org; Fri, 18 Jul 2014 08:20:31 GMT (envelope-from op@FreeBSD.org) Date: Fri, 18 Jul 2014 08:20:31 GMT Message-Id: <201407180820.s6I8KVuQ031526@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271058 - in soc2014/op/freebsd-base/sys: conf kern sys x86/include x86/x86 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jul 2014 08:20:33 -0000 Author: op Date: Fri Jul 18 08:20:31 2014 New Revision: 271058 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271058 Log: KSP: create abstraction for MD parts git: https://github.com/opntr/opBSD/tree/op/gsoc2014/kpatch Signed-off-by: Oliver Pinter --- sys/conf/files.amd64 | 1 + sys/kern/kern_selfpatch.c | 2 ++ sys/sys/selfpatch.h | 9 +++++++++ sys/x86/include/_selfpatch.h | 34 ++++++++++++++++++++++++++++++++++ sys/x86/x86/selfpatch_machdep.c | 40 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 86 insertions(+) create mode 100644 sys/x86/include/_selfpatch.h create mode 100644 sys/x86/x86/selfpatch_machdep.c Added: soc2014/op/freebsd-base/sys/x86/include/_selfpatch.h soc2014/op/freebsd-base/sys/x86/x86/selfpatch_machdep.c Modified: soc2014/op/freebsd-base/sys/conf/files.amd64 soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c soc2014/op/freebsd-base/sys/sys/selfpatch.h Modified: soc2014/op/freebsd-base/sys/conf/files.amd64 ============================================================================== --- soc2014/op/freebsd-base/sys/conf/files.amd64 Fri Jul 18 07:52:35 2014 (r271057) +++ soc2014/op/freebsd-base/sys/conf/files.amd64 Fri Jul 18 08:20:31 2014 (r271058) @@ -554,6 +554,7 @@ x86/x86/nexus.c standard x86/x86/tsc.c standard x86/x86/delay.c standard +x86/x86/selfpatch.c standard x86/xen/hvm.c optional xenhvm x86/xen/xen_intr.c optional xen | xenhvm x86/xen/pv.c optional xenhvm Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c ============================================================================== --- soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 07:52:35 2014 (r271057) +++ soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 08:20:31 2014 (r271058) @@ -37,3 +37,5 @@ #include #include + + Modified: soc2014/op/freebsd-base/sys/sys/selfpatch.h ============================================================================== --- soc2014/op/freebsd-base/sys/sys/selfpatch.h Fri Jul 18 07:52:35 2014 (r271057) +++ soc2014/op/freebsd-base/sys/sys/selfpatch.h Fri Jul 18 08:20:31 2014 (r271058) @@ -26,6 +26,11 @@ * $FreeBSD$ */ +#ifndef __SELFPATH_H__ +#define __SELFPATH_H__ + +#include + typedef struct lf_selfpatch { void *patchable; void *patch; @@ -33,3 +38,7 @@ int feature; char *comment; } lf_selfpatch_t; + +extern char *selfpatch_nop_table[]; + +#endif /* __SELFPATH_H__ */ Added: soc2014/op/freebsd-base/sys/x86/include/_selfpatch.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/op/freebsd-base/sys/x86/include/_selfpatch.h Fri Jul 18 08:20:31 2014 (r271058) @@ -0,0 +1,34 @@ +/*- + * Copyright (c) 2014, by Oliver Pinter + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef __X86_SELFPATH_H__ +#define __X86_SELFPATH_H__ + +extern char *md_selfpatch_nop_table[]; + +#endif /* __X86_SELFPATH_H__ */ Added: soc2014/op/freebsd-base/sys/x86/x86/selfpatch_machdep.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/op/freebsd-base/sys/x86/x86/selfpatch_machdep.c Fri Jul 18 08:20:31 2014 (r271058) @@ -0,0 +1,40 @@ +/*- + * Copyright (c) 2014, by Oliver Pinter + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include + +#include +#include +#include +#include + +#include +#include + +#include + From owner-svn-soc-all@FreeBSD.ORG Fri Jul 18 08:24:31 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 8C61488A for ; Fri, 18 Jul 2014 08:24:31 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6E4DC28BE for ; Fri, 18 Jul 2014 08:24:31 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6I8OVsk078727 for ; Fri, 18 Jul 2014 08:24:31 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s6I8OUpe078533 for svn-soc-all@FreeBSD.org; Fri, 18 Jul 2014 08:24:30 GMT (envelope-from op@FreeBSD.org) Date: Fri, 18 Jul 2014 08:24:30 GMT Message-Id: <201407180824.s6I8OUpe078533@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271059 - in soc2014/op/freebsd-base/sys: amd64/include conf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jul 2014 08:24:31 -0000 Author: op Date: Fri Jul 18 08:24:30 2014 New Revision: 271059 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271059 Log: KSP: fixed build git: https://github.com/opntr/opBSD/tree/op/gsoc2014/kpatch Signed-off-by: Oliver Pinter --- sys/amd64/include/_selfpatch.h | 34 ++++++++++++++++++++++++++++++++++ sys/conf/files.amd64 | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 sys/amd64/include/_selfpatch.h Added: soc2014/op/freebsd-base/sys/amd64/include/_selfpatch.h Modified: soc2014/op/freebsd-base/sys/conf/files.amd64 Added: soc2014/op/freebsd-base/sys/amd64/include/_selfpatch.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/op/freebsd-base/sys/amd64/include/_selfpatch.h Fri Jul 18 08:24:30 2014 (r271059) @@ -0,0 +1,34 @@ +/*- + * Copyright (c) 2014, by Oliver Pinter + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef __AMD64_SELFPATH_H__ +#define __AMD64_SELFPATH_H__ + +#include + +#endif /* __AMD64_SELFPATH_H__ */ Modified: soc2014/op/freebsd-base/sys/conf/files.amd64 ============================================================================== --- soc2014/op/freebsd-base/sys/conf/files.amd64 Fri Jul 18 08:20:31 2014 (r271058) +++ soc2014/op/freebsd-base/sys/conf/files.amd64 Fri Jul 18 08:24:30 2014 (r271059) @@ -554,7 +554,7 @@ x86/x86/nexus.c standard x86/x86/tsc.c standard x86/x86/delay.c standard -x86/x86/selfpatch.c standard +x86/x86/selfpatch_machdep.c standard x86/xen/hvm.c optional xenhvm x86/xen/xen_intr.c optional xen | xenhvm x86/xen/pv.c optional xenhvm From owner-svn-soc-all@FreeBSD.ORG Fri Jul 18 08:27:52 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id E37938D4 for ; Fri, 18 Jul 2014 08:27:52 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B6B7B28D6 for ; Fri, 18 Jul 2014 08:27:52 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6I8RqIo013279 for ; Fri, 18 Jul 2014 08:27:52 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s6I8Rp98013020 for svn-soc-all@FreeBSD.org; Fri, 18 Jul 2014 08:27:51 GMT (envelope-from op@FreeBSD.org) Date: Fri, 18 Jul 2014 08:27:51 GMT Message-Id: <201407180827.s6I8Rp98013020@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271060 - in soc2014/op/freebsd-base/sys: conf kern sys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jul 2014 08:27:53 -0000 Author: op Date: Fri Jul 18 08:27:51 2014 New Revision: 271060 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271060 Log: KSP: added stubs git: https://github.com/opntr/opBSD/tree/op/gsoc2014/kpatch Signed-off-by: Oliver Pinter --- sys/conf/options | 3 +++ sys/kern/kern_selfpatch.c | 14 ++++++++++++++ sys/sys/selfpatch.h | 3 +++ 3 files changed, 20 insertions(+) Modified: soc2014/op/freebsd-base/sys/conf/options soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c soc2014/op/freebsd-base/sys/sys/selfpatch.h Modified: soc2014/op/freebsd-base/sys/conf/options ============================================================================== --- soc2014/op/freebsd-base/sys/conf/options Fri Jul 18 08:24:30 2014 (r271059) +++ soc2014/op/freebsd-base/sys/conf/options Fri Jul 18 08:27:51 2014 (r271060) @@ -925,3 +925,6 @@ RANDOM_FORTUNA opt_random.h RANDOM_DEBUG opt_random.h RANDOM_RWFILE opt_random.h + +# kernel selfpatch +KSP_DEBUG opt_selfpatch.h Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c ============================================================================== --- soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 08:24:30 2014 (r271059) +++ soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 08:27:51 2014 (r271060) @@ -26,6 +26,8 @@ * $FreeBSD$ */ +#include "opt_selfpatch.h" + #include #include @@ -38,4 +40,16 @@ #include +void +lf_selfpatch(linker_file_t lf) +{ + + printf("NOT IMPLEMENTED: %s\n", __func__); +} + +void +lf_selfpatch_apply(linker_file_t lf, struct lf_selfpatch *patch) +{ + printf("NOT IMPLEMENTED: %s\n", __func__); +} Modified: soc2014/op/freebsd-base/sys/sys/selfpatch.h ============================================================================== --- soc2014/op/freebsd-base/sys/sys/selfpatch.h Fri Jul 18 08:24:30 2014 (r271059) +++ soc2014/op/freebsd-base/sys/sys/selfpatch.h Fri Jul 18 08:27:51 2014 (r271060) @@ -41,4 +41,7 @@ extern char *selfpatch_nop_table[]; +void lf_selfpatch(linker_file_t lf); +void lf_selfpatch_apply(linker_file_t lf, struct lf_selfpatch *patch); + #endif /* __SELFPATH_H__ */ From owner-svn-soc-all@FreeBSD.ORG Fri Jul 18 08:48:00 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 65A36E8 for ; Fri, 18 Jul 2014 08:48:00 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 528692A99 for ; Fri, 18 Jul 2014 08:48:00 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6I8m0cE097619 for ; Fri, 18 Jul 2014 08:48:00 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s6I8lxHm097611 for svn-soc-all@FreeBSD.org; Fri, 18 Jul 2014 08:47:59 GMT (envelope-from op@FreeBSD.org) Date: Fri, 18 Jul 2014 08:47:59 GMT Message-Id: <201407180847.s6I8lxHm097611@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271061 - in soc2014/op/freebsd-base/sys: kern x86/include MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jul 2014 08:48:00 -0000 Author: op Date: Fri Jul 18 08:47:59 2014 New Revision: 271061 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271061 Log: KSP: added stubs 2 Signed-off-by: Oliver Pinter git: https://github.com/opntr/opBSD/tree/op/gsoc2014/kpatch Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c soc2014/op/freebsd-base/sys/x86/include/_selfpatch.h Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c ============================================================================== --- soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 08:27:51 2014 (r271060) +++ soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 08:47:59 2014 (r271061) @@ -26,7 +26,7 @@ * $FreeBSD$ */ -#include "opt_selfpatch.h" +//#include "opt_selfpatch.h" #include @@ -40,6 +40,15 @@ #include +bool +lf_selfpatch_patch_needed(struct lf_selfpatch *p) +{ + + printf("NOT IMPLEMENTED: %s\n", __func__); + + return (false); +} + void lf_selfpatch(linker_file_t lf) { Modified: soc2014/op/freebsd-base/sys/x86/include/_selfpatch.h ============================================================================== --- soc2014/op/freebsd-base/sys/x86/include/_selfpatch.h Fri Jul 18 08:27:51 2014 (r271060) +++ soc2014/op/freebsd-base/sys/x86/include/_selfpatch.h Fri Jul 18 08:47:59 2014 (r271061) @@ -29,6 +29,16 @@ #ifndef __X86_SELFPATH_H__ #define __X86_SELFPATH_H__ +#define KSP_CPU_FEATURE 1 +#define KSP_CPU_FEATURE2 2 +#define KSP_AMD_FEATURE 3 +#define KSP_AMD_FEATURE2 4 +#define KSP_VIA_FEATURE_RNG 5 +#define KSP_VIA_FEATURE_XCRYPT 6 +#define KSP_CPU_STDEXT_FEATURE 7 + extern char *md_selfpatch_nop_table[]; +bool lf_selfpatch_patch_needed(struct lf_selfpatch *p); + #endif /* __X86_SELFPATH_H__ */ From owner-svn-soc-all@FreeBSD.ORG Fri Jul 18 08:48:21 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id EBA52FA for ; Fri, 18 Jul 2014 08:48:20 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id CD7222A9B for ; Fri, 18 Jul 2014 08:48:20 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6I8mKqL097824 for ; Fri, 18 Jul 2014 08:48:20 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s6I8mJBM097815 for svn-soc-all@FreeBSD.org; Fri, 18 Jul 2014 08:48:19 GMT (envelope-from op@FreeBSD.org) Date: Fri, 18 Jul 2014 08:48:19 GMT Message-Id: <201407180848.s6I8mJBM097815@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271062 - in soc2014/op/freebsd-base/sys: kern sys x86/include MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jul 2014 08:48:21 -0000 Author: op Date: Fri Jul 18 08:48:19 2014 New Revision: 271062 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271062 Log: KSP: implement lf_selfpatch_patch_needed(struct lf_selfpatch *p) Signed-off-by: Oliver Pinter git: https://github.com/opntr/opBSD/tree/op/gsoc2014/kpatch Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c soc2014/op/freebsd-base/sys/sys/selfpatch.h soc2014/op/freebsd-base/sys/x86/include/_selfpatch.h Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c ============================================================================== --- soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 08:47:59 2014 (r271061) +++ soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 08:48:19 2014 (r271062) @@ -37,14 +37,51 @@ #include #include - #include +#include +#include + bool lf_selfpatch_patch_needed(struct lf_selfpatch *p) { - printf("NOT IMPLEMENTED: %s\n", __func__); + if (p == NULL) + return (false); + + switch (p->feature_selector) { + case KSP_CPU_FEATURE : + if ((cpu_feature & p->feature) != 0) + return (true); + break; + case KSP_CPU_FEATURE2 : + if ((cpu_feature2 & p->feature) != 0) + return (true); + break; + case KSP_AMD_FEATURE : + if ((amd_feature & p->feature) != 0) + return (true); + break; + case KSP_AMD_FEATURE2 : + if ((amd_feature2 & p->feature) != 0) + return (true); + break; + case KSP_VIA_FEATURE_RNG : + if ((via_feature_rng & p->feature) != 0) + return (true); + break; + case KSP_VIA_FEATURE_XCRYPT : + if ((via_feature_xcrypt & p->feature) != 0) + return (true); + break; + case KSP_CPU_STDEXT_FEATURE : + if ((cpu_stdext_feature & p->feature) != 0) + return (true); + break; + + default: + return (false); + } return (false); } Modified: soc2014/op/freebsd-base/sys/sys/selfpatch.h ============================================================================== --- soc2014/op/freebsd-base/sys/sys/selfpatch.h Fri Jul 18 08:47:59 2014 (r271061) +++ soc2014/op/freebsd-base/sys/sys/selfpatch.h Fri Jul 18 08:48:19 2014 (r271062) @@ -31,6 +31,8 @@ #include +struct linker_file_t; + typedef struct lf_selfpatch { void *patchable; void *patch; Modified: soc2014/op/freebsd-base/sys/x86/include/_selfpatch.h ============================================================================== --- soc2014/op/freebsd-base/sys/x86/include/_selfpatch.h Fri Jul 18 08:47:59 2014 (r271061) +++ soc2014/op/freebsd-base/sys/x86/include/_selfpatch.h Fri Jul 18 08:48:19 2014 (r271062) @@ -37,6 +37,8 @@ #define KSP_VIA_FEATURE_XCRYPT 6 #define KSP_CPU_STDEXT_FEATURE 7 +struct lf_selfpatch; + extern char *md_selfpatch_nop_table[]; bool lf_selfpatch_patch_needed(struct lf_selfpatch *p); From owner-svn-soc-all@FreeBSD.ORG Fri Jul 18 08:48:33 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 3E50318F for ; Fri, 18 Jul 2014 08:48:33 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 2C1982AA2 for ; Fri, 18 Jul 2014 08:48:33 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6I8mXdw097944 for ; Fri, 18 Jul 2014 08:48:33 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s6I8mW1p097940 for svn-soc-all@FreeBSD.org; Fri, 18 Jul 2014 08:48:32 GMT (envelope-from op@FreeBSD.org) Date: Fri, 18 Jul 2014 08:48:32 GMT Message-Id: <201407180848.s6I8mW1p097940@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271063 - soc2014/op/freebsd-base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jul 2014 08:48:33 -0000 Author: op Date: Fri Jul 18 08:48:32 2014 New Revision: 271063 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271063 Log: added .gitignore Signed-off-by: Oliver Pinter git: https://github.com/opntr/opBSD/tree/op/gsoc2014/kpatch Added: soc2014/op/freebsd-base/.gitignore Added: soc2014/op/freebsd-base/.gitignore ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/op/freebsd-base/.gitignore Fri Jul 18 08:48:32 2014 (r271063) @@ -0,0 +1 @@ +.clang_complete From owner-svn-soc-all@FreeBSD.ORG Fri Jul 18 08:48:46 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 2517B1A5 for ; Fri, 18 Jul 2014 08:48:46 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id EC8262AA7 for ; Fri, 18 Jul 2014 08:48:45 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6I8mjxI098048 for ; Fri, 18 Jul 2014 08:48:45 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s6I8mjqk098043 for svn-soc-all@FreeBSD.org; Fri, 18 Jul 2014 08:48:45 GMT (envelope-from op@FreeBSD.org) Date: Fri, 18 Jul 2014 08:48:45 GMT Message-Id: <201407180848.s6I8mjqk098043@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271064 - in soc2014/op/freebsd-base/sys: kern sys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jul 2014 08:48:46 -0000 Author: op Date: Fri Jul 18 08:48:44 2014 New Revision: 271064 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271064 Log: KSP: implemented basic kernel patching Signed-off-by: Oliver Pinter git: https://github.com/opntr/opBSD/tree/op/gsoc2014/kpatch Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c soc2014/op/freebsd-base/sys/sys/selfpatch.h Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c ============================================================================== --- soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 08:48:32 2014 (r271063) +++ soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 08:48:44 2014 (r271064) @@ -42,6 +42,7 @@ #include #include + bool lf_selfpatch_patch_needed(struct lf_selfpatch *p) { @@ -89,13 +90,28 @@ void lf_selfpatch(linker_file_t lf) { + struct lf_selfpatch *patch, *start, *stop; + int count, ret; + + ret = linker_file_lookup_set(lf, "ksp_kpatch_set", &start, &stop, &count); + if (ret != 0) { + printf("linker_file_lookup_set faild to locate ksp_kpatch_set\n"); + return; + } - printf("NOT IMPLEMENTED: %s\n", __func__); + for (patch = start; patch != stop; patch++) { + lf_selfpatch_apply(lf, patch); + } } void -lf_selfpatch_apply(linker_file_t lf, struct lf_selfpatch *patch) +lf_selfpatch_apply(linker_file_t lf, struct lf_selfpatch *p) { + if (!lf_selfpatch_patch_needed(p)) + return; + + KASSERT(p->patch_size == p->patchable_size, + ("%s: patch_size != patchable_size", __func__)); - printf("NOT IMPLEMENTED: %s\n", __func__); + memcpy(p->patchable, p->patch, p->patchable_size); } Modified: soc2014/op/freebsd-base/sys/sys/selfpatch.h ============================================================================== --- soc2014/op/freebsd-base/sys/sys/selfpatch.h Fri Jul 18 08:48:32 2014 (r271063) +++ soc2014/op/freebsd-base/sys/sys/selfpatch.h Fri Jul 18 08:48:44 2014 (r271064) @@ -36,7 +36,9 @@ typedef struct lf_selfpatch { void *patchable; void *patch; - short feature_selector; + int patchable_size; + int patch_size; + int feature_selector; int feature; char *comment; } lf_selfpatch_t; From owner-svn-soc-all@FreeBSD.ORG Fri Jul 18 08:48:56 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 1001F1B6 for ; Fri, 18 Jul 2014 08:48:56 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id F19F92AA8 for ; Fri, 18 Jul 2014 08:48:55 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6I8mtur098195 for ; Fri, 18 Jul 2014 08:48:55 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s6I8mtAE098179 for svn-soc-all@FreeBSD.org; Fri, 18 Jul 2014 08:48:55 GMT (envelope-from op@FreeBSD.org) Date: Fri, 18 Jul 2014 08:48:55 GMT Message-Id: <201407180848.s6I8mtAE098179@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271065 - soc2014/op/freebsd-base/sys/amd64/amd64 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jul 2014 08:48:56 -0000 Author: op Date: Fri Jul 18 08:48:55 2014 New Revision: 271065 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271065 Log: KSP: hook in kernel patching at hammer_time Signed-off-by: Oliver Pinter git: https://github.com/opntr/opBSD/tree/op/gsoc2014/kpatch Modified: soc2014/op/freebsd-base/sys/amd64/amd64/machdep.c Modified: soc2014/op/freebsd-base/sys/amd64/amd64/machdep.c ============================================================================== --- soc2014/op/freebsd-base/sys/amd64/amd64/machdep.c Fri Jul 18 08:48:44 2014 (r271064) +++ soc2014/op/freebsd-base/sys/amd64/amd64/machdep.c Fri Jul 18 08:48:55 2014 (r271065) @@ -81,6 +81,7 @@ #include #include #include +#include #include #ifdef SMP #include @@ -1998,6 +1999,9 @@ initializecpu(); /* Initialize CPU registers */ initializecpucache(); + /* selfmodify kernel text, when needed */ + lf_selfpatch(linker_kernel_file); + /* doublefault stack space, runs on ist1 */ common_tss[0].tss_ist1 = (long)&dblfault_stack[sizeof(dblfault_stack)]; From owner-svn-soc-all@FreeBSD.ORG Fri Jul 18 08:49:10 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 57DAA1CF for ; Fri, 18 Jul 2014 08:49:10 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 39B122AAD for ; Fri, 18 Jul 2014 08:49:10 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6I8nAIj098385 for ; Fri, 18 Jul 2014 08:49:10 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s6I8n93l098369 for svn-soc-all@FreeBSD.org; Fri, 18 Jul 2014 08:49:09 GMT (envelope-from op@FreeBSD.org) Date: Fri, 18 Jul 2014 08:49:09 GMT Message-Id: <201407180849.s6I8n93l098369@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271066 - soc2014/op/freebsd-base/sys/kern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jul 2014 08:49:10 -0000 Author: op Date: Fri Jul 18 08:49:09 2014 New Revision: 271066 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271066 Log: KSP: in early initialization the linker_kernel_file yet not initialized, workaround this sitation Breakpoint 2, trap (frame=0xffffffff814e5b60) at /usr/data/source/git/opBSD/opBSD.git/sys/amd64/amd64/trap.c:170 170 { Current language: auto; currently minimal (kgdb) bt at /usr/data/source/git/opBSD/opBSD.git/sys/amd64/amd64/exception.S:231 firstp=0xffffffff814e5c70, lastp=0xffffffff814e5c68, countp=0xffffffff814e5c64) at linker_if.h:97 at /usr/data/source/git/opBSD/opBSD.git/sys/kern/kern_selfpatch.c:103 at /usr/data/source/git/opBSD/opBSD.git/sys/amd64/amd64/machdep.c:2003 (kgdb) bt full regs = {r_r15 = 0, r_r14 = -2125570972, r_r13 = 2000, r_r12 = 394758, r_r11 = 0, r_r10 = -2125570992, r_r9 = 2000, r_r8 = 2000, r_rdi = -2125570960, r_rsi = -2129194576, r_rbp = -2125570972, r_rbx = -2125570968, r_rdx = 11259170867118089, r_rcx = 0, r_rax = 11259170867118081, r_trapno = 0, r_fs = 0, r_gs = 0, r_err = 2156834140, r_es = 65535, r_ds = 65535, r_rip = 32, r_cs = 134, r_rflags = -2125571040, r_rsp = 40, r_ss = 4294967295} ksi = {ksi_link = {tqe_next = 0xffffffff81971e80, tqe_prev = 0xffffffff814c8fd8}, ksi_info = { si_signo = 29831168, si_errno = 0, si_code = -2125570960, si_pid = -1, si_uid = 2156714019, si_status = -1, si_addr = 0xffffffff81c6c000, si_value = {sival_int = -1, sival_ptr = 0xffffffff, sigval_int = -1, sigval_ptr = 0xffffffff}, _reason = {_fault = {_trapno = -2125571040}, _timer = { _timerid = -2125571040, _overrun = -1}, _mesgq = {_mqd = -2125571040}, _poll = { _band = -2125571040}, __spare__ = {__spare1__ = -2125571040, __spare2__ = {-2137744547, -1, 5, -1, -2133847262, -1, -2124770176}}}}, ksi_flags = -2125974920, ksi_sigq = 0xf000ff53f000ff53} td = addr = ucode = i = p = type = code = at /usr/data/source/git/opBSD/opBSD.git/sys/amd64/amd64/exception.S:231 No locals. firstp=0xffffffff814e5c70, lastp=0xffffffff814e5c68, countp=0xffffffff814e5c64) at linker_if.h:97 No locals. at /usr/data/source/git/opBSD/opBSD.git/sys/kern/kern_selfpatch.c:103 start = (struct lf_selfpatch *) 0xffffffff814e5c80 stop = (struct lf_selfpatch *) 0x1c73000 count = -1 ret = patch = at /usr/data/source/git/opBSD/opBSD.git/sys/amd64/amd64/machdep.c:2003 kmdp = 0xffffffff81c6c000 "\001" env = No locals. No symbol table info available. (kgdb) p link Display all 106 possibilities? (y or n) (kgdb) p linker_kernel_file $1 = 0x0 Signed-off-by: Oliver Pinter git: https://github.com/opntr/opBSD/tree/op/gsoc2014/kpatch Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c ============================================================================== --- soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 08:48:55 2014 (r271065) +++ soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 08:49:09 2014 (r271066) @@ -42,14 +42,23 @@ #include #include +#define DBG(...) \ + if (bootverbose) { \ + printf("%s: ", __func__); \ + printf(__VA_ARGS__); \ + } + +extern struct lf_selfpatch __start_set_ksp_kpatch_set[]; +extern struct lf_selfpatch __stop_set_ksp_kpatch_set[]; + bool lf_selfpatch_patch_needed(struct lf_selfpatch *p) { - if (p == NULL) return (false); + switch (p->feature_selector) { case KSP_CPU_FEATURE : if ((cpu_feature & p->feature) != 0) @@ -93,13 +102,25 @@ struct lf_selfpatch *patch, *start, *stop; int count, ret; - ret = linker_file_lookup_set(lf, "ksp_kpatch_set", &start, &stop, &count); - if (ret != 0) { - printf("linker_file_lookup_set faild to locate ksp_kpatch_set\n"); - return; + if (lf != NULL) { + ret = linker_file_lookup_set(lf, "ksp_kpatch_set", &start, &stop, NULL); + DBG("start: %p stop: %p\n", start, stop); + if (ret != 0) { + DBG("failed to locate ksp_kpatch_set\n"); + return; + } + } else { + DBG("kernel patching\n"); + DBG("start: %p stop: %p\n", __start_set_ksp_kpatch_set, __stop_set_ksp_kpatch_set); + start = __stop_set_ksp_kpatch_set; + stop = __stop_set_ksp_kpatch_set; } + count = stop - start; + DBG("count: %d\n", count); + for (patch = start; patch != stop; patch++) { + DBG("apply: %p\n", patch); lf_selfpatch_apply(lf, patch); } } From owner-svn-soc-all@FreeBSD.ORG Fri Jul 18 08:52:00 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id BE583203 for ; Fri, 18 Jul 2014 08:52:00 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id ABCEE2B2B for ; Fri, 18 Jul 2014 08:52:00 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6I8q0pP014536 for ; Fri, 18 Jul 2014 08:52:00 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s6I8q096014383 for svn-soc-all@FreeBSD.org; Fri, 18 Jul 2014 08:52:00 GMT (envelope-from op@FreeBSD.org) Date: Fri, 18 Jul 2014 08:52:00 GMT Message-Id: <201407180852.s6I8q096014383@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271067 - soc2014/op/tools MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jul 2014 08:52:00 -0000 Author: op Date: Fri Jul 18 08:51:59 2014 New Revision: 271067 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271067 Log: updated tools/svn-cherry-pick-from-git.csh added git log support Signed-off-by: Oliver Pinter Modified: soc2014/op/tools/svn-cherry-pick-from-git.csh Modified: soc2014/op/tools/svn-cherry-pick-from-git.csh ============================================================================== --- soc2014/op/tools/svn-cherry-pick-from-git.csh Fri Jul 18 08:49:09 2014 (r271066) +++ soc2014/op/tools/svn-cherry-pick-from-git.csh Fri Jul 18 08:51:59 2014 (r271067) @@ -3,6 +3,7 @@ set ver=$1 set td=`mktemp -d` set opwd=${PWD} +set GIT_DIR=${opwd}/.git set svndir="/usr/data/source/svn/op/freebsd-base" git format-patch -o ${td} ${ver} @@ -10,10 +11,34 @@ cd ${svndir} foreach i ( `ls ${td}` ) + clear set i=${td}/${i} + echo "PATCH: ${i}" + set files=`sed -n -e 's/ \(.*\).*|.* [0-9]*.*$/\1/gp' ${i}` + echo "FILES: ${files}" + echo "press ENTER to continue" + $< + less ${i} patch -p1 < ${i} - svnlite commit + svnlite add ${files} + echo + echo "press ENTER to continue" + $< + set git_id=`sed -n -e '/From/s/From \([0-9a-f]*\) .*/\1/p' ${i}` + git --git-dir=${GIT_DIR} show --format="%s%n%n%b%ngit: https://github.com/opntr/opBSD/tree/op/gsoc2014/kpatch" -s ${git_id} > /tmp/svn-commit-message-${git_id}.txt + echo + cat /tmp/svn-commit-message-${git_id}.txt + echo "press ENTER to continue" + $< + svnlite commit -F /tmp/svn-commit-message-${git_id}.txt end +svnlite up + +find . -type f -name "*.orig" +echo "press ENTER to delete .orig files" +$< +find . -type f -name "*.orig" -delete + cd ${PWD} From owner-svn-soc-all@FreeBSD.ORG Fri Jul 18 10:02:55 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 420A942B for ; Fri, 18 Jul 2014 10:02:55 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 2F0C12132 for ; Fri, 18 Jul 2014 10:02:55 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6IA2ta3041262 for ; Fri, 18 Jul 2014 10:02:55 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s6IA2set041165 for svn-soc-all@FreeBSD.org; Fri, 18 Jul 2014 10:02:54 GMT (envelope-from op@FreeBSD.org) Date: Fri, 18 Jul 2014 10:02:54 GMT Message-Id: <201407181002.s6IA2set041165@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271071 - soc2014/op/freebsd-base/sys/kern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jul 2014 10:02:55 -0000 Author: op Date: Fri Jul 18 10:02:54 2014 New Revision: 271071 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271071 Log: KSP: added debug code Signed-off-by: Oliver Pinter git: https://github.com/opntr/opBSD/tree/op/gsoc2014/kpatch Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c ============================================================================== --- soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 08:23:53 2014 (r271070) +++ soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 10:02:54 2014 (r271071) @@ -38,12 +38,13 @@ #include #include #include +#include #include #include #define DBG(...) \ - if (bootverbose) { \ + if (selfpatch_debug) { \ printf("%s: ", __func__); \ printf(__VA_ARGS__); \ } @@ -51,13 +52,18 @@ extern struct lf_selfpatch __start_set_ksp_kpatch_set[]; extern struct lf_selfpatch __stop_set_ksp_kpatch_set[]; +static int selfpatch_debug=1; +SYSCTL_INT(_debug, OID_AUTO, selfpatch_debug, CTLFLAG_RWTUN, + &selfpatch_debug, 0, "Set various levels of selfpatch debug"); bool lf_selfpatch_patch_needed(struct lf_selfpatch *p) { - if (p == NULL) - return (false); + if (p == NULL) { + DBG("false\n"); + return (false); + } switch (p->feature_selector) { case KSP_CPU_FEATURE : @@ -134,5 +140,7 @@ KASSERT(p->patch_size == p->patchable_size, ("%s: patch_size != patchable_size", __func__)); + DBG("%p\n", p->patch); + memcpy(p->patchable, p->patch, p->patchable_size); } From owner-svn-soc-all@FreeBSD.ORG Fri Jul 18 10:03:04 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 782FD43F for ; Fri, 18 Jul 2014 10:03:04 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 656852135 for ; Fri, 18 Jul 2014 10:03:04 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6IA34qK042687 for ; Fri, 18 Jul 2014 10:03:04 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s6IA33Ii042582 for svn-soc-all@FreeBSD.org; Fri, 18 Jul 2014 10:03:03 GMT (envelope-from op@FreeBSD.org) Date: Fri, 18 Jul 2014 10:03:03 GMT Message-Id: <201407181003.s6IA33Ii042582@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271072 - soc2014/op/freebsd-base/sys/kern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jul 2014 10:03:04 -0000 Author: op Date: Fri Jul 18 10:03:03 2014 New Revision: 271072 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271072 Log: KSP: print the patchable kernel object name Signed-off-by: Oliver Pinter git: https://github.com/opntr/opBSD/tree/op/gsoc2014/kpatch Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c ============================================================================== --- soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 10:02:54 2014 (r271071) +++ soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 10:03:03 2014 (r271072) @@ -109,12 +109,13 @@ int count, ret; if (lf != NULL) { + DBG("module: %s\n", lf->filename); ret = linker_file_lookup_set(lf, "ksp_kpatch_set", &start, &stop, NULL); - DBG("start: %p stop: %p\n", start, stop); if (ret != 0) { DBG("failed to locate ksp_kpatch_set\n"); return; } + DBG("start: %p stop: %p\n", start, stop); } else { DBG("kernel patching\n"); DBG("start: %p stop: %p\n", __start_set_ksp_kpatch_set, __stop_set_ksp_kpatch_set); From owner-svn-soc-all@FreeBSD.ORG Fri Jul 18 10:03:15 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 323D5457 for ; Fri, 18 Jul 2014 10:03:15 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1F4E7213A for ; Fri, 18 Jul 2014 10:03:15 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6IA3ENe044490 for ; Fri, 18 Jul 2014 10:03:14 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s6IA3E5q044322 for svn-soc-all@FreeBSD.org; Fri, 18 Jul 2014 10:03:14 GMT (envelope-from op@FreeBSD.org) Date: Fri, 18 Jul 2014 10:03:14 GMT Message-Id: <201407181003.s6IA3E5q044322@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271073 - soc2014/op/freebsd-base/sys/kern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jul 2014 10:03:15 -0000 Author: op Date: Fri Jul 18 10:03:14 2014 New Revision: 271073 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271073 Log: KSP: hook in lf_selfpatch in kldload and preload case Signed-off-by: Oliver Pinter git: https://github.com/opntr/opBSD/tree/op/gsoc2014/kpatch Modified: soc2014/op/freebsd-base/sys/kern/kern_linker.c Modified: soc2014/op/freebsd-base/sys/kern/kern_linker.c ============================================================================== --- soc2014/op/freebsd-base/sys/kern/kern_linker.c Fri Jul 18 10:03:03 2014 (r271072) +++ soc2014/op/freebsd-base/sys/kern/kern_linker.c Fri Jul 18 10:03:14 2014 (r271073) @@ -53,6 +53,7 @@ #include #include #include +#include #include @@ -420,6 +421,7 @@ return (error); } modules = !TAILQ_EMPTY(&lf->modules); + lf_selfpatch(lf); linker_file_register_sysctls(lf); linker_file_sysinit(lf); lf->flags |= LINKER_FILE_LINKED; @@ -1607,6 +1609,8 @@ lf->filename); goto fail; } + /* XXXOP - linker_kernel_file double patched?*/ + lf_selfpatch(lf); linker_file_register_modules(lf); if (linker_file_lookup_set(lf, "sysinit_set", &si_start, &si_stop, NULL) == 0) From owner-svn-soc-all@FreeBSD.ORG Fri Jul 18 10:35:40 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 84978837 for ; Fri, 18 Jul 2014 10:35:40 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7150723DB for ; Fri, 18 Jul 2014 10:35:40 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6IAZedv047587 for ; Fri, 18 Jul 2014 10:35:40 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s6IAZdfW047380 for svn-soc-all@FreeBSD.org; Fri, 18 Jul 2014 10:35:39 GMT (envelope-from op@FreeBSD.org) Date: Fri, 18 Jul 2014 10:35:39 GMT Message-Id: <201407181035.s6IAZdfW047380@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271074 - in soc2014/op/freebsd-base/sys: conf kern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jul 2014 10:35:40 -0000 Author: op Date: Fri Jul 18 10:35:39 2014 New Revision: 271074 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271074 Log: KSP: rename ELF sets Signed-off-by: Oliver Pinter git: https://github.com/opntr/opBSD/tree/op/gsoc2014/kpatch Modified: soc2014/op/freebsd-base/sys/conf/ldscript.amd64 soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Modified: soc2014/op/freebsd-base/sys/conf/ldscript.amd64 ============================================================================== --- soc2014/op/freebsd-base/sys/conf/ldscript.amd64 Fri Jul 18 10:03:14 2014 (r271073) +++ soc2014/op/freebsd-base/sys/conf/ldscript.amd64 Fri Jul 18 10:35:39 2014 (r271074) @@ -30,10 +30,10 @@ .rela.data : { *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) } .rel.tdata : { *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*) } .rela.tdata : { *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) } - .rel.set_ksp_kpatch_set : { *(.rel.set_ksp_kpatch_set) } - .rela.set_ksp_kpatch_set : { *(.rela.set_ksp_kpatch_set) } - .rel.set_ksp_kpatch_patch_set : { *(.rel.set_ksp_kpatch_patch_set) } - .rela.set_ksp_kpatch_patch_set : { *(.rela.set_ksp_kpatch_patch_set) } + .rel.set_selfpatch_set : { *(.rel.set_selfpatch_set) } + .rela.set_selfpatch_set : { *(.rela.set_selfpatch_set) } + .rel.set_selfpatch_patch_set : { *(.rel.set_selfpatch_patch_set) } + .rela.set_selfpatch_patch_set : { *(.rela.set_selfpatch_patch_set) } .rel.tbss : { *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*) } .rela.tbss : { *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) } .rel.ctors : { *(.rel.ctors) } @@ -144,17 +144,17 @@ .got : { *(.got) } . = DATA_SEGMENT_RELRO_END (24, .); .got.plt : { *(.got.plt) } - set_ksp_kpatch_set : + set_selfpatch_set : { - PROVIDE ( __start_set_ksp_kpatch_set = . ); - KEEP (*(set_ksp_kpatch_set)); - PROVIDE ( __stop_set_ksp_kpatch_set = . ); + PROVIDE ( __start_set_selfpatch_set = . ); + KEEP (*(set_selfpatch_set)); + PROVIDE ( __stop_set_selfpatch_set = . ); } - set_ksp_kpatch_patch_set : + set_selfpatch_patch_set : { - PROVIDE ( __start_set_ksp_kpatch_patch_set = . ); - KEEP (*(set_ksp_kpatch_patch_set)); - PROVIDE ( __stop_set_ksp_kpatch_patch_set = . ); + PROVIDE ( __start_set_selfpatch_patch_set = . ); + KEEP (*(set_selfpatch_patch_set)); + PROVIDE ( __stop_set_selfpatch_patch_set = . ); } .data : { Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c ============================================================================== --- soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 10:03:14 2014 (r271073) +++ soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 10:35:39 2014 (r271074) @@ -49,8 +49,8 @@ printf(__VA_ARGS__); \ } -extern struct lf_selfpatch __start_set_ksp_kpatch_set[]; -extern struct lf_selfpatch __stop_set_ksp_kpatch_set[]; +extern struct lf_selfpatch __start_set_selfpatch_set[]; +extern struct lf_selfpatch __stop_set_selfpatch_set[]; static int selfpatch_debug=1; SYSCTL_INT(_debug, OID_AUTO, selfpatch_debug, CTLFLAG_RWTUN, @@ -110,17 +110,17 @@ if (lf != NULL) { DBG("module: %s\n", lf->filename); - ret = linker_file_lookup_set(lf, "ksp_kpatch_set", &start, &stop, NULL); + ret = linker_file_lookup_set(lf, "selfpatch_set", &start, &stop, NULL); if (ret != 0) { - DBG("failed to locate ksp_kpatch_set\n"); + DBG("failed to locate selfpatch_set\n"); return; } DBG("start: %p stop: %p\n", start, stop); } else { DBG("kernel patching\n"); - DBG("start: %p stop: %p\n", __start_set_ksp_kpatch_set, __stop_set_ksp_kpatch_set); - start = __stop_set_ksp_kpatch_set; - stop = __stop_set_ksp_kpatch_set; + DBG("start: %p stop: %p\n", __start_set_selfpatch_set, __stop_set_selfpatch_set); + start = __stop_set_selfpatch_set; + stop = __stop_set_selfpatch_set; } count = stop - start; From owner-svn-soc-all@FreeBSD.ORG Fri Jul 18 13:54:31 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id F1A234A9 for ; Fri, 18 Jul 2014 13:54:31 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D292426E4 for ; Fri, 18 Jul 2014 13:54:31 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6IDsV2T088721 for ; Fri, 18 Jul 2014 13:54:31 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s6IDsUMX088697 for svn-soc-all@FreeBSD.org; Fri, 18 Jul 2014 13:54:30 GMT (envelope-from dpl@FreeBSD.org) Date: Fri, 18 Jul 2014 13:54:30 GMT Message-Id: <201407181354.s6IDsUMX088697@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271079 - in soc2014/dpl/netmap-ipfwjit: . sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jul 2014 13:54:32 -0000 Author: dpl Date: Fri Jul 18 13:54:29 2014 New Revision: 271079 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271079 Log: Modularized the code and modified Makefiles, there's "only" all the LLVM stuff left. Added: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.c - copied, changed from r271013, soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.cc soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.h Deleted: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.cc Modified: soc2014/dpl/netmap-ipfwjit/Makefile soc2014/dpl/netmap-ipfwjit/Makefile.kipfw Modified: soc2014/dpl/netmap-ipfwjit/Makefile ============================================================================== --- soc2014/dpl/netmap-ipfwjit/Makefile Fri Jul 18 12:51:35 2014 (r271078) +++ soc2014/dpl/netmap-ipfwjit/Makefile Fri Jul 18 13:54:29 2014 (r271079) @@ -26,7 +26,7 @@ clean: -@rm -rf $(OBJDIR) kipfw @(cd ipfw && $(MAKE) clean ) - @rm ./ip_fw_rules.bc + @rm -f ./ip_fw_rules.bc tgz: @$(MAKE) clean Modified: soc2014/dpl/netmap-ipfwjit/Makefile.kipfw ============================================================================== --- soc2014/dpl/netmap-ipfwjit/Makefile.kipfw Fri Jul 18 12:51:35 2014 (r271078) +++ soc2014/dpl/netmap-ipfwjit/Makefile.kipfw Fri Jul 18 13:54:29 2014 (r271079) @@ -136,8 +136,7 @@ EFILES = $(foreach i,$(EDIRS),$(subst $(empty) , $(i)/, $(EFILES_$(i): = ))) BCFLAGS=-emit-llvm -c -CXX=clang++ -CXXFLAGS= $(CFLAGS) `llvm-config-devel --cxxflags --libs jit support` +CXXFLAGS= `llvm-config-devel --cxxflags --libs jit support` include_e: -@echo "Building $(OBJPATH)/include_e ..." @@ -149,13 +148,14 @@ $(IPFW_OBJS) : ../extra/glue.h ip_fw2.o ip_dummynet.o: # EFLAGS= -include missing.h +ip_fw2.o: jit.o radix.o:# CFLAGS += -U_KERNEL # session.o: CFLAGS = -O2 nm_util.o: CFLAGS = -O2 -Wall -Werror $(NETMAP_FLAGS) -$(MOD): $(IPFW_OBJS) ../ip_fw_rules.bc +$(MOD): $(IPFW_OBJS) ../ip_fw_rules.bc jit.o $(MSG) " LD $@" $(HIDE)$(CC) -o $@ $^ $(LIBS) @@ -163,9 +163,8 @@ ../ip_fw_rules.bc: @$(CC) $(CFLAGS) $(BCFLAGS) -o ../ip_fw_rules.bc ../sys/netpfil/ipfw/ip_fw_rules.h -ip_fw2.o: ip_fw2.cc - @echo "Building ip_fw2.cc" - clang++ $(CXXFLAGS) ../sys/netpfil/ipfw/ip_fw2.cc -o ./ip_fw2.o +jit.o: jit.cc + @clang++ $(CXXFLAGS) ../sys/netpfil/ipfw/jit.cc -o ./jit.o clean: -rm -f *.o $(DN) $(MOD) Copied and modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.c (from r271013, soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.cc) ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.cc Thu Jul 17 09:48:34 2014 (r271013, copy source) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.c Fri Jul 18 13:54:29 2014 (r271079) @@ -39,6 +39,7 @@ #include "opt_inet6.h" #include "opt_ipsec.h" #include "ip_fw_rules.h" +#include "jit.h" #include #include @@ -230,6 +231,9 @@ static inline void rule_nat(struct ip_fw_args *, int, struct ip_fw_chain *, ipfw_insn *, struct mbuf *, uint32_t, int *, int *, int *); static inline void rule_reass(struct ip_fw *, int, struct ip_fw_chain *, int, struct ip *, struct ip_fw_args *, struct mbuf *, int *, int *, int *); +/* JIT compiling API */ +static void ipfw_jit_init(); + /* * Each rule belongs to one of 32 different sets (0..31). * The variable set_disable contains one bit per set. @@ -1319,20 +1323,7 @@ default_fw_tables = IPFW_TABLES_MAX; ipfw_log_bpf(1); /* init */ - -#include -#include -#include - -using namespace llvm; - - /* JIT */ - Module *Mod; - LLVMContext &C; - /* We load the bc for JIT compilation */ - char *buffer; - MemoryBuffer::getFile("ip_fw_rules.bc", buffer); - Module *Mod = ParseBitcodeFile(buffer.get(), C); + ipfw_jit_init(); return (error); } Added: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Fri Jul 18 13:54:29 2014 (r271079) @@ -0,0 +1,24 @@ +/* JIT compilation code */ +#include +#include +#include +#include +#include +#include + +using namespace llvm; + +ErrorOr ptr; +Module *mod; +LLVMContext con; +LLVMContext &c = con; +OwningPtr buffer; + +static void +ipfw_jit_init() +{ + ptr = mod; + /* We load the bc for JIT compilation */ + MemoryBuffer::getFile("ip_fw_rules.bc", buffer); + ptr = parseBitcodeFile(buffer.get(), c); +} Added: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.h Fri Jul 18 13:54:29 2014 (r271079) @@ -0,0 +1,2 @@ + +static void ipfw_jit_init(); From owner-svn-soc-all@FreeBSD.ORG Fri Jul 18 16:01:41 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 855A3EE9 for ; Fri, 18 Jul 2014 16:01:41 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 57C2D2375 for ; Fri, 18 Jul 2014 16:01:41 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6IG1f2T028710 for ; Fri, 18 Jul 2014 16:01:41 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s6IG1eE2028371 for svn-soc-all@FreeBSD.org; Fri, 18 Jul 2014 16:01:40 GMT (envelope-from op@FreeBSD.org) Date: Fri, 18 Jul 2014 16:01:40 GMT Message-Id: <201407181601.s6IG1eE2028371@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271083 - in soc2014/op/freebsd-base/sys/amd64: amd64 include MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jul 2014 16:01:41 -0000 Author: op Date: Fri Jul 18 16:01:40 2014 New Revision: 271083 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271083 Log: KSP: change pmap_kenter_attr(vm_offset_t va, vm_paddr_t pa, int mode) visibility Signed-off-by: Oliver Pinter git: https://github.com/opntr/opBSD/tree/op/gsoc2014/kpatch Modified: soc2014/op/freebsd-base/sys/amd64/amd64/pmap.c soc2014/op/freebsd-base/sys/amd64/include/pmap.h Modified: soc2014/op/freebsd-base/sys/amd64/amd64/pmap.c ============================================================================== --- soc2014/op/freebsd-base/sys/amd64/amd64/pmap.c Fri Jul 18 15:39:07 2014 (r271082) +++ soc2014/op/freebsd-base/sys/amd64/amd64/pmap.c Fri Jul 18 16:01:40 2014 (r271083) @@ -429,7 +429,6 @@ vm_page_t m, vm_prot_t prot, vm_page_t mpte, struct rwlock **lockp); static void pmap_fill_ptp(pt_entry_t *firstpte, pt_entry_t newpte); static int pmap_insert_pt_page(pmap_t pmap, vm_page_t mpte); -static void pmap_kenter_attr(vm_offset_t va, vm_paddr_t pa, int mode); static vm_page_t pmap_lookup_pt_page(pmap_t pmap, vm_offset_t va); static void pmap_pde_attr(pd_entry_t *pde, int cache_bits, int mask); static void pmap_promote_pde(pmap_t pmap, pd_entry_t *pde, vm_offset_t va, @@ -1925,7 +1924,7 @@ pte_store(pte, pa | X86_PG_RW | X86_PG_V | X86_PG_G); } -static __inline void +__inline void pmap_kenter_attr(vm_offset_t va, vm_paddr_t pa, int mode) { pt_entry_t *pte; Modified: soc2014/op/freebsd-base/sys/amd64/include/pmap.h ============================================================================== --- soc2014/op/freebsd-base/sys/amd64/include/pmap.h Fri Jul 18 15:39:07 2014 (r271082) +++ soc2014/op/freebsd-base/sys/amd64/include/pmap.h Fri Jul 18 16:01:40 2014 (r271083) @@ -380,6 +380,7 @@ void pmap_demote_DMAP(vm_paddr_t base, vm_size_t len, boolean_t invalidate); void pmap_init_pat(void); void pmap_kenter(vm_offset_t va, vm_paddr_t pa); +void pmap_kenter_attr(vm_offset_t va, vm_paddr_t pa, int mode); void *pmap_kenter_temporary(vm_paddr_t pa, int i); vm_paddr_t pmap_kextract(vm_offset_t); void pmap_kremove(vm_offset_t); From owner-svn-soc-all@FreeBSD.ORG Fri Jul 18 16:07:59 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 77528FC for ; Fri, 18 Jul 2014 16:07:59 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 643E423C5 for ; Fri, 18 Jul 2014 16:07:59 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6IG7x0A052228 for ; Fri, 18 Jul 2014 16:07:59 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s6IG7wqp052226 for svn-soc-all@FreeBSD.org; Fri, 18 Jul 2014 16:07:58 GMT (envelope-from op@FreeBSD.org) Date: Fri, 18 Jul 2014 16:07:58 GMT Message-Id: <201407181607.s6IG7wqp052226@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271084 - soc2014/op/tools MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jul 2014 16:07:59 -0000 Author: op Date: Fri Jul 18 16:07:58 2014 New Revision: 271084 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271084 Log: fixed regex in tools/svn-cherry-pick-from-git.csh Signed-off-by: Oliver Pinter Modified: soc2014/op/tools/svn-cherry-pick-from-git.csh Modified: soc2014/op/tools/svn-cherry-pick-from-git.csh ============================================================================== --- soc2014/op/tools/svn-cherry-pick-from-git.csh Fri Jul 18 16:01:40 2014 (r271083) +++ soc2014/op/tools/svn-cherry-pick-from-git.csh Fri Jul 18 16:07:58 2014 (r271084) @@ -14,7 +14,7 @@ clear set i=${td}/${i} echo "PATCH: ${i}" - set files=`sed -n -e 's/ \(.*\).*|.* [0-9]*.*$/\1/gp' ${i}` + set files=`sed -n -e 's/^ \(.*\).*|.* [0-9]*.*$/\1/gp' ${i}` echo "FILES: ${files}" echo "press ENTER to continue" $< From owner-svn-soc-all@FreeBSD.ORG Fri Jul 18 16:08:28 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 663D9145 for ; Fri, 18 Jul 2014 16:08:28 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 3FA1F23CE for ; Fri, 18 Jul 2014 16:08:28 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6IG8SpN052625 for ; Fri, 18 Jul 2014 16:08:28 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s6IG8RXh052608 for svn-soc-all@FreeBSD.org; Fri, 18 Jul 2014 16:08:27 GMT (envelope-from op@FreeBSD.org) Date: Fri, 18 Jul 2014 16:08:27 GMT Message-Id: <201407181608.s6IG8RXh052608@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271085 - in soc2014/op/freebsd-base/sys: kern sys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jul 2014 16:08:28 -0000 Author: op Date: Fri Jul 18 16:08:27 2014 New Revision: 271085 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271085 Log: KSP: change destination memory region from RX to RWX, and after patching back to RX Signed-off-by: Oliver Pinter git: https://github.com/opntr/opBSD/tree/op/gsoc2014/kpatch Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c soc2014/op/freebsd-base/sys/sys/selfpatch.h Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c ============================================================================== --- soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 16:07:58 2014 (r271084) +++ soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 16:08:27 2014 (r271085) @@ -34,12 +34,16 @@ #include #include #include +#include #include #include #include #include +#include +#include + #include #include @@ -135,13 +139,49 @@ void lf_selfpatch_apply(linker_file_t lf, struct lf_selfpatch *p) { + vm_paddr_t *pages; + vm_offset_t page_offset; + int i, page_number; + if (!lf_selfpatch_patch_needed(p)) return; KASSERT(p->patch_size == p->patchable_size, ("%s: patch_size != patchable_size", __func__)); - DBG("%p\n", p->patch); + page_offset = (vm_offset_t)p->patchable & (vm_offset_t)PAGE_MASK; + page_number = (p->patchable_size >> PAGE_SHIFT) + + ((page_offset + p->patchable_size) > PAGE_SIZE ? 2 : 1); + + pages = malloc(page_number, M_TEMP, M_WAITOK | M_ZERO); + + DBG("change mapping attribute from RX to RWX\n"); + for (i=0; ipatchable) + i * PAGE_SIZE; + pages[i] = pmap_kextract(kva); + pmap_kenter_attr(kva, pages[i], VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE); + } + DBG("done.\n"); + + DBG("patchable: %p\n", p->patchable); + DBG("patch: %p\n", p->patch); + DBG("patch size: %d\n", p->patchable_size); memcpy(p->patchable, p->patch, p->patchable_size); + + DBG("patched.\n"); + + DBG("change mapping attribute from RWX to RX:\n"); + for (i=0; ipatchable) + i * PAGE_SIZE; + pmap_kenter_attr(kva, pages[i], VM_PROT_READ | VM_PROT_EXECUTE); + } + DBG("done.\n"); + + free(pages, M_TEMP); } + Modified: soc2014/op/freebsd-base/sys/sys/selfpatch.h ============================================================================== --- soc2014/op/freebsd-base/sys/sys/selfpatch.h Fri Jul 18 16:07:58 2014 (r271084) +++ soc2014/op/freebsd-base/sys/sys/selfpatch.h Fri Jul 18 16:08:27 2014 (r271085) @@ -34,8 +34,8 @@ struct linker_file_t; typedef struct lf_selfpatch { - void *patchable; - void *patch; + char *patchable; + char *patch; int patchable_size; int patch_size; int feature_selector; From owner-svn-soc-all@FreeBSD.ORG Fri Jul 18 16:09:47 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 52886164 for ; Fri, 18 Jul 2014 16:09:47 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 3EF1A23D6 for ; Fri, 18 Jul 2014 16:09:47 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6IG9lJt053728 for ; Fri, 18 Jul 2014 16:09:47 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s6IG9kNw053711 for svn-soc-all@FreeBSD.org; Fri, 18 Jul 2014 16:09:46 GMT (envelope-from op@FreeBSD.org) Date: Fri, 18 Jul 2014 16:09:46 GMT Message-Id: <201407181609.s6IG9kNw053711@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271086 - in soc2014/op/freebsd-base/sys: kern sys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jul 2014 16:09:47 -0000 Author: op Date: Fri Jul 18 16:09:46 2014 New Revision: 271086 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271086 Log: KSP: added selftest Signed-off-by: Oliver Pinter git: https://github.com/opntr/opBSD/tree/op/gsoc2014/kpatch Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c soc2014/op/freebsd-base/sys/sys/selfpatch.h Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c ============================================================================== --- soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 16:08:27 2014 (r271085) +++ soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 16:09:46 2014 (r271086) @@ -60,6 +60,8 @@ SYSCTL_INT(_debug, OID_AUTO, selfpatch_debug, CTLFLAG_RWTUN, &selfpatch_debug, 0, "Set various levels of selfpatch debug"); +void lf_selfpatch_selftest(void); + bool lf_selfpatch_patch_needed(struct lf_selfpatch *p) { @@ -70,35 +72,38 @@ } switch (p->feature_selector) { - case KSP_CPU_FEATURE : + case KSP_CPU_FEATURE : if ((cpu_feature & p->feature) != 0) return (true); break; - case KSP_CPU_FEATURE2 : + case KSP_CPU_FEATURE2 : if ((cpu_feature2 & p->feature) != 0) return (true); break; - case KSP_AMD_FEATURE : + case KSP_AMD_FEATURE : if ((amd_feature & p->feature) != 0) return (true); break; - case KSP_AMD_FEATURE2 : + case KSP_AMD_FEATURE2 : if ((amd_feature2 & p->feature) != 0) return (true); break; - case KSP_VIA_FEATURE_RNG : + case KSP_VIA_FEATURE_RNG : if ((via_feature_rng & p->feature) != 0) return (true); break; - case KSP_VIA_FEATURE_XCRYPT : + case KSP_VIA_FEATURE_XCRYPT : if ((via_feature_xcrypt & p->feature) != 0) return (true); break; - case KSP_CPU_STDEXT_FEATURE : + case KSP_CPU_STDEXT_FEATURE : if ((cpu_stdext_feature & p->feature) != 0) return (true); break; - + case KSP_SELFTEST: + if ((p->feature & KSP_FEATURE_SELFTEST) != 0) + return (true); + break; default: return (false); } @@ -134,6 +139,11 @@ DBG("apply: %p\n", patch); lf_selfpatch_apply(lf, patch); } + + /* + * when selfpatch does not works, the system should crash + */ + lf_selfpatch_selftest(); } void @@ -143,6 +153,14 @@ vm_offset_t page_offset; int i, page_number; + DBG("patchable: %p\n", p->patchable); + DBG("patch: %p\n", p->patch); + DBG("feature selector: %d\n", p->feature_selector); + DBG("feature: %d\n", p->feature); + DBG("patchable size: %d\n", p->patchable_size); + DBG("patch size: %d\n", p->patch_size); + DBG("comment: %s\n", p->comment); + if (!lf_selfpatch_patch_needed(p)) return; @@ -185,3 +203,30 @@ free(pages, M_TEMP); } + +void +lf_selfpatch_selftest(void) +{ + __asm __volatile( + "1:" + " .byte 0xde,0xad,0xde,0xad ; " + "2: " + " .pushsection set_selfpatch_patch_set, \"ax\" ; " + "3: " + " .byte 0x90,0x90,0x90,0x90 ;" + "4: " + " .popsection " + " .pushsection set_selfpatch_set, \"a\" ; " + " .quad 1b ; " + " .quad 3b ; " + " .int 2b-1b ; " + " .int 4b-3b ; " + " .int 0 ; " + " .int 1 ; " + " .quad 0 ; " + " .popsection ; " + ); + + DBG("works.\n"); +} + Modified: soc2014/op/freebsd-base/sys/sys/selfpatch.h ============================================================================== --- soc2014/op/freebsd-base/sys/sys/selfpatch.h Fri Jul 18 16:08:27 2014 (r271085) +++ soc2014/op/freebsd-base/sys/sys/selfpatch.h Fri Jul 18 16:09:46 2014 (r271086) @@ -29,6 +29,9 @@ #ifndef __SELFPATH_H__ #define __SELFPATH_H__ +#define KSP_SELFTEST 0 +#define KSP_FEATURE_SELFTEST 1 + #include struct linker_file_t; From owner-svn-soc-all@FreeBSD.ORG Fri Jul 18 16:09:58 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id BF99A179 for ; Fri, 18 Jul 2014 16:09:58 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id AC7C823D9 for ; Fri, 18 Jul 2014 16:09:58 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6IG9waJ053877 for ; Fri, 18 Jul 2014 16:09:58 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s6IG9wwE053861 for svn-soc-all@FreeBSD.org; Fri, 18 Jul 2014 16:09:58 GMT (envelope-from op@FreeBSD.org) Date: Fri, 18 Jul 2014 16:09:58 GMT Message-Id: <201407181609.s6IG9wwE053861@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271087 - soc2014/op/freebsd-base/sys/kern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jul 2014 16:09:58 -0000 Author: op Date: Fri Jul 18 16:09:57 2014 New Revision: 271087 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271087 Log: KSP: fixed a typo ... Signed-off-by: Oliver Pinter git: https://github.com/opntr/opBSD/tree/op/gsoc2014/kpatch Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c ============================================================================== --- soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 16:09:46 2014 (r271086) +++ soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 16:09:57 2014 (r271087) @@ -128,7 +128,7 @@ } else { DBG("kernel patching\n"); DBG("start: %p stop: %p\n", __start_set_selfpatch_set, __stop_set_selfpatch_set); - start = __stop_set_selfpatch_set; + start = __start_set_selfpatch_set; stop = __stop_set_selfpatch_set; } From owner-svn-soc-all@FreeBSD.ORG Fri Jul 18 16:10:07 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 4E75518B for ; Fri, 18 Jul 2014 16:10:07 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 3940423DC for ; Fri, 18 Jul 2014 16:10:07 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6IGA7N2055013 for ; Fri, 18 Jul 2014 16:10:07 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s6IGA6Nm055010 for svn-soc-all@FreeBSD.org; Fri, 18 Jul 2014 16:10:06 GMT (envelope-from op@FreeBSD.org) Date: Fri, 18 Jul 2014 16:10:06 GMT Message-Id: <201407181610.s6IGA6Nm055010@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271088 - soc2014/op/freebsd-base/sys/kern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jul 2014 16:10:07 -0000 Author: op Date: Fri Jul 18 16:10:06 2014 New Revision: 271088 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271088 Log: KSP: malloc does not exists in early stage of initialization, not use them Signed-off-by: Oliver Pinter git: https://github.com/opntr/opBSD/tree/op/gsoc2014/kpatch Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c ============================================================================== --- soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 16:09:57 2014 (r271087) +++ soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 16:10:06 2014 (r271088) @@ -149,7 +149,11 @@ void lf_selfpatch_apply(linker_file_t lf, struct lf_selfpatch *p) { +#if 0 vm_paddr_t *pages; +#else + vm_paddr_t pages[4]; +#endif vm_offset_t page_offset; int i, page_number; @@ -171,7 +175,12 @@ page_number = (p->patchable_size >> PAGE_SHIFT) + ((page_offset + p->patchable_size) > PAGE_SIZE ? 2 : 1); +#if 0 pages = malloc(page_number, M_TEMP, M_WAITOK | M_ZERO); +#else + KASSERT(page_number < 4, + ("patch size longer than 3 page does not supported yet\n")); +#endif DBG("change mapping attribute from RX to RWX\n"); for (i=0; i Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 1995C19E for ; Fri, 18 Jul 2014 16:10:16 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0660A23DE for ; Fri, 18 Jul 2014 16:10:16 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6IGAFsd055185 for ; Fri, 18 Jul 2014 16:10:15 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s6IGAFvk055168 for svn-soc-all@FreeBSD.org; Fri, 18 Jul 2014 16:10:15 GMT (envelope-from op@FreeBSD.org) Date: Fri, 18 Jul 2014 16:10:15 GMT Message-Id: <201407181610.s6IGAFvk055168@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271089 - soc2014/op/freebsd-base/sys/kern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jul 2014 16:10:16 -0000 Author: op Date: Fri Jul 18 16:10:15 2014 New Revision: 271089 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271089 Log: KSP: remove redundant debug message, and fix one Signed-off-by: Oliver Pinter git: https://github.com/opntr/opBSD/tree/op/gsoc2014/kpatch Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c ============================================================================== --- soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 16:10:06 2014 (r271088) +++ soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 16:10:15 2014 (r271089) @@ -182,7 +182,7 @@ ("patch size longer than 3 page does not supported yet\n")); #endif - DBG("change mapping attribute from RX to RWX\n"); + DBG("change mapping attribute from RX to RWX:\n"); for (i=0; ipatchable); - DBG("patch: %p\n", p->patch); - DBG("patch size: %d\n", p->patchable_size); - memcpy(p->patchable, p->patch, p->patchable_size); DBG("patched.\n"); From owner-svn-soc-all@FreeBSD.ORG Fri Jul 18 16:10:38 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B4DEE1B2 for ; Fri, 18 Jul 2014 16:10:38 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 94A9A23E1 for ; Fri, 18 Jul 2014 16:10:38 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6IGAc8X056280 for ; Fri, 18 Jul 2014 16:10:38 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s6IGAcE8056266 for svn-soc-all@FreeBSD.org; Fri, 18 Jul 2014 16:10:38 GMT (envelope-from op@FreeBSD.org) Date: Fri, 18 Jul 2014 16:10:38 GMT Message-Id: <201407181610.s6IGAcE8056266@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271090 - soc2014/op/freebsd-base/sys/kern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jul 2014 16:10:38 -0000 Author: op Date: Fri Jul 18 16:10:37 2014 New Revision: 271090 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271090 Log: KSP: disallow inlining of lf_selfpatch_selftest, and change test bytes Signed-off-by: Oliver Pinter git: https://github.com/opntr/opBSD/tree/op/gsoc2014/kpatch Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c ============================================================================== --- soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 16:10:15 2014 (r271089) +++ soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Fri Jul 18 16:10:37 2014 (r271090) @@ -60,7 +60,7 @@ SYSCTL_INT(_debug, OID_AUTO, selfpatch_debug, CTLFLAG_RWTUN, &selfpatch_debug, 0, "Set various levels of selfpatch debug"); -void lf_selfpatch_selftest(void); +__noinline void lf_selfpatch_selftest(void); bool lf_selfpatch_patch_needed(struct lf_selfpatch *p) @@ -211,12 +211,12 @@ } -void +__noinline void lf_selfpatch_selftest(void) { __asm __volatile( "1:" - " .byte 0xde,0xad,0xde,0xad ; " + " ud2; ud2; ; " "2: " " .pushsection set_selfpatch_patch_set, \"ax\" ; " "3: " From owner-svn-soc-all@FreeBSD.ORG Sat Jul 19 07:23:16 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 40944E45 for ; Sat, 19 Jul 2014 07:23:16 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 2BA5A2071 for ; Sat, 19 Jul 2014 07:23:16 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6J7NGB9057698 for ; Sat, 19 Jul 2014 07:23:16 GMT (envelope-from seiya@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s6J7NFQd057534 for svn-soc-all@FreeBSD.org; Sat, 19 Jul 2014 07:23:15 GMT (envelope-from seiya@FreeBSD.org) Date: Sat, 19 Jul 2014 07:23:15 GMT Message-Id: <201407190723.s6J7NFQd057534@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to seiya@FreeBSD.org using -f From: seiya@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271117 - in soc2014/seiya/bootsplash: etc sys/dev/fb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 19 Jul 2014 07:23:16 -0000 Author: seiya Date: Sat Jul 19 07:23:14 2014 New Revision: 271117 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271117 Log: support a progress bar Modified: soc2014/seiya/bootsplash/etc/rc soc2014/seiya/bootsplash/sys/dev/fb/bsplash.c Modified: soc2014/seiya/bootsplash/etc/rc ============================================================================== --- soc2014/seiya/bootsplash/etc/rc Sat Jul 19 06:27:24 2014 (r271116) +++ soc2014/seiya/bootsplash/etc/rc Sat Jul 19 07:23:14 2014 (r271117) @@ -124,7 +124,18 @@ fi files=`rcorder ${skip} ${skip_firstboot} /etc/rc.d/* ${local_rc} 2>/dev/null` +files_num=`echo "$files" | wc -l` +files_num_per_10=`expr $files_num / 10` # FIXME +i=0 +BOOT_PROGRESS=0 for _rc_elem in ${files}; do + i=`expr $i + 1` + if [ $files_num_per_10 -eq $i ]; then + BOOT_PROGRESS=`expr $BOOT_PROGRESS + 10` + kenv BOOT_PROGRESS=$BOOT_PROGRESS > /dev/null + i=0 + fi + case "$_rc_elem_done" in *" $_rc_elem "*) continue ;; esac Modified: soc2014/seiya/bootsplash/sys/dev/fb/bsplash.c ============================================================================== --- soc2014/seiya/bootsplash/sys/dev/fb/bsplash.c Sat Jul 19 06:27:24 2014 (r271116) +++ soc2014/seiya/bootsplash/sys/dev/fb/bsplash.c Sat Jul 19 07:23:14 2014 (r271117) @@ -59,7 +59,14 @@ static int animation_x = -1; static int animation_width = -1; static int animation_height = -1; -static int animation_enabled = 1; +static int animation_enabled = 1; // 1:enabled, 0:disabled +static int progress_bar_y_origin = -1; +static int progress_bar_y = -1; +static int progress_bar_x = -1; +static int progress_bar_width = -1; +static int progress_bar_height = -1; +static int progress_bar_enabled = 1; // 1:enabled, 0:disabled + int bsplash_early_init(video_adapter_t *_adp) @@ -141,6 +148,56 @@ } freeenv(s); + // load "bsplash_progress_bar_y_origin" + if ((s = getenv("bsplash_progress_bar_y_origin")) == NULL) { + if (bootverbose) + printf("bsplash: cannot load \"bsplash_progress_bar_y_origin\"\n"); + progress_bar_enabled = 0; + } else { + progress_bar_y_origin = strtol(s, NULL, 10); + } + freeenv(s); + + // load "bsplash_progress_bar_y" + if ((s = getenv("bsplash_progress_bar_y")) == NULL) { + if (bootverbose) + printf("bsplash: cannot load \"bsplash_progress_bar_y\"\n"); + progress_bar_enabled = 0; + } else { + progress_bar_y = strtol(s, NULL, 10); + } + freeenv(s); + + // load "bsplash_progress_bar_x" + if ((s = getenv("bsplash_progress_bar_x")) == NULL) { + if (bootverbose) + printf("bsplash: cannot load \"bsplash_progress_bar_x\"\n"); + progress_bar_enabled = 0; + } else { + progress_bar_x = strtol(s, NULL, 10); + } + freeenv(s); + + // load "bsplash_progress_bar_height" + if ((s = getenv("bsplash_progress_bar_height")) == NULL) { + if (bootverbose) + printf("bsplash: cannot load \"bsplash_progress_bar_height\"\n"); + progress_bar_enabled = 0; + } else { + progress_bar_height = strtol(s, NULL, 10); + } + freeenv(s); + + // load "bsplash_progress_bar_width" + if ((s = getenv("bsplash_progress_bar_width")) == NULL) { + if (bootverbose) + printf("bsplash: cannot load \"bsplash_progress_bar_width\"\n"); + progress_bar_enabled = 0; + } else { + progress_bar_width = strtol(s, NULL, 10); + } + freeenv(s); + /* * for debugging */ @@ -155,6 +212,13 @@ animation_y_origin, animation_height, animation_width); + printf("bsplash: progress bar is %s (y,x)=(%d,%d), img_y=%d, height=%d, width=%d\n", + (progress_bar_enabled)? "enabled" : "disabled", + progress_bar_y, + progress_bar_x, + progress_bar_y_origin, + progress_bar_height, + progress_bar_width); } /* @@ -223,8 +287,11 @@ freeenv(s); } - // boot takes too long - if (progress >= 100 || count > 50 /* FXIME */){ + // update the progress bar + draw_bmp(progress_bar_y_origin + ((progress / 10) * progress_bar_height), + progress_bar_y, progress_bar_x, progress_bar_width, progress_bar_height); + + if (progress >= 100 /* boot has finished */ || count > 50 /* FIX